Wild Life  2.30
 All Data Structures Files Functions Variables Typedefs Macros
Functions | Variables
types.c File Reference

types More...

Go to the source code of this file.

Functions

void print_def_type (def_type t)
 print_def_type More...
 
long yes_or_no ()
 yes_or_no More...
 
void remove_cycles (ptr_definition d, ptr_int_list *dl)
 remove_cycles More...
 
long redefine (ptr_psi_term t)
 redefine More...
 
ptr_int_list cons (GENERIC v, ptr_int_list l)
 cons More...
 
long assert_less (ptr_psi_term t1, ptr_psi_term t2)
 assert_less More...
 
void assert_protected (ptr_node n, long prot)
 assert_protected More...
 
void assert_args_not_eval (ptr_node n)
 assert_args_not_eval More...
 
void assert_delay_check (ptr_node n)
 assert_delay_check More...
 
void clear_already_loaded (ptr_node n)
 clear_already_loaded More...
 
void assert_type (ptr_psi_term t)
 assert_type More...
 
void assert_complicated_type (ptr_psi_term t)
 assert_complicated_type More...
 
void assert_attributes (ptr_psi_term t)
 assert_attributes More...
 
void find_adults ()
 find_adults More...
 
void insert_own_prop (ptr_definition d)
 insert_own_prop More...
 
void insert_prop (ptr_definition d, ptr_triple_list prop)
 insert_prop More...
 
void propagate_definitions ()
 propagate_definitions More...
 
long count_sorts (long c0)
 count_sorts More...
 
void clear_coding ()
 clear_coding More...
 
void least_sorts ()
 void least_sorts() More...
 
void all_sorts ()
 all_sorts More...
 
ptr_int_list two_to_the (long p)
 two_to_the More...
 
ptr_int_list copyTypeCode (ptr_int_list u)
 copyTypeCode More...
 
void or_codes (ptr_int_list u, ptr_int_list v)
 or_codes More...
 
void equalize_codes (int len)
 equalize_codes More...
 
void make_type_link (ptr_definition t1, ptr_definition t2)
 make_type_link More...
 
long type_member (ptr_definition t, ptr_int_list tlst)
 type_member More...
 
void perr_sort (ptr_definition d)
 perr_sort More...
 
void perr_sort_list (ptr_int_list anc)
 perr_sort_list More...
 
void perr_sort_cycle (ptr_int_list anc)
 perr_sort_cycle More...
 
long type_cyclicity (ptr_definition d, ptr_int_list anc)
 type_cyclicity More...
 
void propagate_always_check (ptr_definition d, long *ch)
 propagate_always_check More...
 
void one_pass_always_check (long *ch)
 one_pass_always_check More...
 
void inherit_always_check ()
 inherit_always_check More...
 
void encode_types ()
 encode_types More...
 
void print_codes ()
 print_codes More...
 
long glb_value (long result, long f, GENERIC c, GENERIC value1, GENERIC value2, GENERIC *value)
 glb_value More...
 
long glb_code (long f1, GENERIC c1, long f2, GENERIC c2, long *f3, GENERIC *c3)
 glb_code More...
 
long glb (ptr_definition t1, ptr_definition t2, ptr_definition *t3, ptr_int_list *c3)
 glb More...
 
long overlap_type (ptr_definition t1, ptr_definition t2)
 overlap_type More...
 
long sub_CodeType (ptr_int_list c1, ptr_int_list c2)
 sub_CodeType More...
 
long sub_type (ptr_definition t1, ptr_definition t2)
 sub_type More...
 
long matches (ptr_definition t1, ptr_definition t2, long *smaller)
 matches More...
 
long strict_matches (ptr_psi_term t1, ptr_psi_term t2, long *smaller)
 strict_matches More...
 
long bit_length (ptr_int_list c)
 bit_length More...
 
ptr_int_list decode (ptr_int_list c)
 decode More...
 

Variables

ptr_definitiongamma_table = NULL
 

Detailed Description

types

These routines implement type encoding using the "Transitive Closure" binary encoding algorithm.

Definition in file types.c.

Function Documentation

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.

760 {
761  ptr_definition d;
762 
763  for(d=first_definition;d;d=d->next)
764  if (d->type_def==(def_type)type_it && d!=nothing)
766 }
ptr_definition nothing
symbol in bi module
Definition: def_glob.h:347
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
def_type type_def
Definition: def_struct.h:153
ptr_int_list cons(GENERIC v, ptr_int_list l)
cons
Definition: types.c:179
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
ptr_definition next
Definition: def_struct.h:164
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_int_list parents
Definition: def_struct.h:151
void assert_args_not_eval ( ptr_node  n)

assert_args_not_eval

Parameters
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().

295 {
296  ptr_psi_term t;
297 
298  if (n) {
300 
301  t=(ptr_psi_term)n->data;
302  deref_ptr(t);
303  if (t->type) {
304  if (t->type->type_def==(def_type)type_it) {
305  warningline("'%s' is a sort--only functions and predicates\
306  can have unevaluated arguments.\n",t->type->keyword->symbol);
307  }
308  else
310  }
311 
313  }
314 }
char evaluate_args
Definition: def_struct.h:156
void assert_args_not_eval(ptr_node n)
assert_args_not_eval
Definition: types.c:294
def_type type_def
Definition: def_struct.h:153
ptr_keyword keyword
Definition: def_struct.h:147
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
char * symbol
Definition: def_struct.h:118
ptr_node left
Definition: def_struct.h:199
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
#define deref_ptr(P)
Definition: def_macro.h:100
#define FALSE
Standard boolean.
Definition: def_const.h:275
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
ptr_node right
Definition: def_struct.h:200
void assert_attributes ( ptr_psi_term  t)

assert_attributes

Parameters
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.

501 {
502  ptr_psi_term arg1,arg2,pred=NULL,typ;
503  ptr_definition d;
504 
505  get_two_args(t->attr_list,&arg1,&arg2);
506 
507  if (arg1) {
508  typ=arg1;
509  deref_ptr(arg1);
510  if (!strcmp(arg1->type->keyword->symbol,"|")) {
511  get_two_args(arg1->attr_list,&arg1,&pred);
512  if (arg1) {
513  typ=arg1;
514  deref_ptr(arg1);
515  }
516  }
517 
518  if (arg1 && wl_const_3(*arg1)) {
519  /* if (!redefine(arg1)) return; RM: Feb 19 1993 */
520  d=arg1->type;
522  Errorline("the %T '%s' may not be redefined as a sort.\n",
523  d->type_def, d->keyword->symbol);
524  }
525  else {
528  add_rule(typ,pred,(def_type)type_it);
529  }
530  }
531  else {
532  Errorline("bad argument in sort declaration '%P' (%E).\n",t);
533  }
534  }
535  else {
536  Errorline("argument missing in sort declaration (%E).\n");
537  }
538 }
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
struct wl_definition * def_type
Definition: def_struct.h:60
def_type type_def
Definition: def_struct.h:153
#define predicate_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1401
ptr_keyword keyword
Definition: def_struct.h:147
#define NULL
Definition: def_const.h:533
char * symbol
Definition: def_struct.h:118
long types_modified
Definition: def_glob.h:1022
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define wl_const_3(S)
Definition: def_macro.h:109
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
void add_rule(ptr_psi_term head, ptr_psi_term body, def_type typ)
add_rule
Definition: login.c:167
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
void assert_complicated_type ( ptr_psi_term  t)

assert_complicated_type

Parameters
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().

406 {
407  ptr_psi_term arg2,typ1,typ2,pred=NULL;
408  // ptr_list lst;
409  long eqflag = equ_tok((*t),":=");
410  long ok, any_ok=FALSE;
411 
412  get_two_args(t->attr_list,&typ1,&arg2);
413 
414  if (typ1 && arg2) {
415  deref_ptr(typ1);
416  deref_ptr(arg2);
417  typ2=arg2;
418  if (!strcmp(arg2->type->keyword->symbol,"|")) {
419  typ2=NULL;
420  get_two_args(arg2->attr_list,&arg2,&pred);
421  if (arg2) {
422  deref_ptr(arg2);
423  typ2=arg2;
424  }
425  }
426  if (typ2) {
427  if (typ2->type==disjunction) {
428 
429  if (typ1->attr_list && eqflag) {
430  warningline("attributes ignored left of ':=' declaration (%E).\n");
431  }
432  while(typ2 && typ2->type!=nil) {
433  get_two_args(typ2->attr_list,&arg2,&typ2); /* RM: Dec 14 1992 */
434  if(typ2)
435  deref_ptr(typ2);
436  if (arg2) {
437  deref_ptr(arg2);
438  if (eqflag) {
439  ok=assert_less(arg2,typ1);
440  if (ok) any_ok=TRUE;
441  if (ok && (arg2->attr_list || pred!=NULL)) {
442  add_rule(arg2,pred,(def_type)type_it);
443  }
444  }
445  else {
446  ok=assert_less(typ1,arg2);
447  if (ok) any_ok=TRUE;
448  if (ok && arg2->attr_list) {
449  warningline("attributes ignored in sort declaration (%E).\n");
450  }
451  }
452  }
453  }
454  assert_ok=TRUE;
455  }
456  else if (eqflag) {
457  if (typ1->attr_list) {
458  warningline("attributes ignored left of ':=' declaration (%E).\n");
459  }
460  ok=assert_less(typ1,typ2);
461  if (ok) any_ok=TRUE;
462  typ2->type=typ1->type;
463  if (ok && (typ2->attr_list || pred!=NULL))
464  add_rule(typ2,pred,(def_type)type_it);
465  else
466  assert_ok=TRUE;
467  }
468  else {
469  if (typ2->attr_list) {
470  warningline("attributes ignored right of '<|' declaration (%E).\n");
471  }
472  ok=assert_less(typ1,typ2);
473  if (ok) any_ok=TRUE;
474  if (ok && (typ1->attr_list || pred!=NULL))
475  add_rule(typ1,pred,(def_type)type_it);
476  else
477  assert_ok=TRUE;
478  }
479  }
480  else {
481  Errorline("argument missing in sort declaration (%E).\n");
482  }
483  }
484  else {
485  Errorline("argument missing in sort declaration (%E).\n");
486  }
487  if (!any_ok) assert_ok=FALSE;
488 }
ptr_definition disjunction
symbol in bi module
Definition: def_glob.h:249
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
long assert_less(ptr_psi_term t1, ptr_psi_term t2)
assert_less
Definition: types.c:200
ptr_keyword keyword
Definition: def_struct.h:147
#define NULL
Definition: def_const.h:533
char * symbol
Definition: def_struct.h:118
long assert_ok
Definition: def_glob.h:1033
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_definition nil
symbol in bi module
Definition: def_glob.h:340
#define equ_tok(A, B)
Definition: def_macro.h:67
void add_rule(ptr_psi_term head, ptr_psi_term body, def_type typ)
add_rule
Definition: login.c:167
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
void assert_delay_check ( ptr_node  n)

assert_delay_check

Parameters
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.

327 {
328  if (n) {
329  ptr_psi_term t;
331 
332  t=(ptr_psi_term)n->data;
333  deref_ptr(t);
334  if (t->type) {
335  t->type->always_check=FALSE;
336  }
337 
339  }
340 }
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
char always_check
Definition: def_struct.h:154
ptr_node left
Definition: def_struct.h:199
#define deref_ptr(P)
Definition: def_macro.h:100
#define FALSE
Standard boolean.
Definition: def_const.h:275
void assert_delay_check(ptr_node n)
assert_delay_check
Definition: types.c:326
ptr_definition type
Definition: def_struct.h:181
ptr_node right
Definition: def_struct.h:200
long assert_less ( ptr_psi_term  t1,
ptr_psi_term  t2 
)

assert_less

Parameters
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.

201 {
202  ptr_definition d1,d2;
203  long ok=FALSE;
204  deref_ptr(t1);
205  deref_ptr(t2);
206 
207  if (t1->type==top) {
208  Errorline("the top sort '@' may not be a subsort.\n");
209  return FALSE;
210  }
211  if (t1->value_3 || t2->value_3) {
212  Errorline("the declaration '%P <| %P' is illegal.\n",t1,t2);
213  return FALSE;
214  }
215  /* Note: A *full* cyclicity check of the hierarchy is done in encode_types. */
216  if (t1->type==t2->type) {
217  Errorline("cyclic sort declarations are not allowed.\n");
218  return FALSE;
219  }
220 
221  if (!redefine(t1)) return FALSE;
222  if (!redefine(t2)) return FALSE;
223  d1=t1->type;
224  d2=t2->type;
226  Errorline("the %T '%s' may not be redefined as a sort.\n",
227  d1->type_def, d1->keyword->symbol);
228  }
229  else if (d2->type_def==(def_type)predicate_it || d2->type_def==(def_type)function_it) {
230  Errorline("the %T '%s' may not be redefined as a sort.\n",
231  d2->type_def, d2->keyword->symbol);
232  }
233  else {
237  make_type_link(d1, d2); /* 1.7 */
238  /* d1->parents=cons(d2,d1->parents); */
239  /* d2->children=cons(d1,d2->children); */
240  ok=TRUE;
241  }
242 
243  return ok;
244 }
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
struct wl_definition * def_type
Definition: def_struct.h:60
long redefine(ptr_psi_term t)
redefine
Definition: types.c:104
def_type type_def
Definition: def_struct.h:153
#define predicate_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1401
ptr_keyword keyword
Definition: def_struct.h:147
char * symbol
Definition: def_struct.h:118
long types_modified
Definition: def_glob.h:1022
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
void make_type_link(ptr_definition t1, ptr_definition t2)
make_type_link
Definition: types.c:901
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC value_3
Definition: def_struct.h:186
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
ptr_definition type
Definition: def_struct.h:181
void assert_protected ( ptr_node  n,
long  prot 
)

assert_protected

Parameters
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().

256 {
257  ptr_psi_term t;
258 
259  if (n) {
260  assert_protected(n->left,prot);
261 
262  t=(ptr_psi_term)n->data;
263  deref_ptr(t);
264  if (t->type) {
265  if (t->type->type_def==(def_type)type_it) {
266  warningline("'%s' is a sort. It can be extended without a declaration.\n",
267  t->type->keyword->symbol);
268  }
269  else if ((unsigned long)t->type->rule<MAX_BUILT_INS &&
270  (unsigned long)t->type->rule>0) {
271  if (!prot)
272  warningline("'%s' is a built-in--it has not been made dynamic.\n",
273  t->type->keyword->symbol);
274  }
275  else {
276  t->type->protected=prot;
277  if (prot) t->type->date&=(~1); else t->type->date|=1;
278  }
279  }
280 
281  assert_protected(n->right,prot);
282  }
283 }
def_type type_def
Definition: def_struct.h:153
ptr_keyword keyword
Definition: def_struct.h:147
void assert_protected(ptr_node n, long prot)
assert_protected
Definition: types.c:255
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
char * symbol
Definition: def_struct.h:118
ptr_node left
Definition: def_struct.h:199
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
#define deref_ptr(P)
Definition: def_macro.h:100
ptr_pair_list rule
Definition: def_struct.h:148
#define MAX_BUILT_INS
Maximum number of built_ins.
Definition: def_const.h:154
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
ptr_node right
Definition: def_struct.h:200
void assert_type ( ptr_psi_term  t)

assert_type

Parameters
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.

373 {
374  ptr_psi_term arg1,arg2;
375 
376  get_two_args(t->attr_list,&arg1,&arg2);
377  if(arg1==NULL || arg2==NULL) {
378  Errorline("bad sort declaration '%P' (%E).\n",t);
379  }
380  else
381  assert_ok=assert_less(arg1,arg2);
382 }
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
long assert_less(ptr_psi_term t1, ptr_psi_term t2)
assert_less
Definition: types.c:200
#define NULL
Definition: def_const.h:533
long assert_ok
Definition: def_glob.h:1033
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
ptr_node attr_list
Definition: def_struct.h:187
long bit_length ( ptr_int_list  c)

bit_length

Parameters
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.

1754 {
1755  unsigned long p=0,dp=0,v=0,dv=0;
1756 
1757  while (c) {
1758  v=(unsigned long)c->value_1;
1759  if(v) {
1760  dp=p;
1761  dv=v;
1762  }
1763  c=c->next;
1764  p=p+INT_SIZE;
1765  }
1766 
1767  while (dv) {
1768  dp++;
1769  dv=dv>>1;
1770  }
1771 
1772  return dp;
1773 }
#define INT_SIZE
How many types can be encoded on one integer in the transitive closure encoding.
Definition: def_const.h:317
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list next
Definition: def_struct.h:86
void clear_already_loaded ( ptr_node  n)

clear_already_loaded

Parameters
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.

352 {
353  ptr_definition d;
354 
355  if (n) {
356  d=((ptr_keyword)n->data)->definition;
360  }
361 }
char already_loaded
Definition: def_struct.h:157
void clear_already_loaded(ptr_node n)
clear_already_loaded
Definition: types.c:351
GENERIC data
Definition: def_struct.h:201
ptr_node left
Definition: def_struct.h:199
#define FALSE
Standard boolean.
Definition: def_const.h:275
struct wl_keyword * ptr_keyword
Definition: def_struct.h:125
ptr_node right
Definition: def_struct.h:200
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.

728 {
729  ptr_definition d;
730 
731  for(d=first_definition;d;d=d->next)
732  if (d->type_def==(def_type)type_it) d->code=NOT_CODED;
733 }
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
def_type type_def
Definition: def_struct.h:153
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
ptr_definition next
Definition: def_struct.h:164
ptr_int_list code
Definition: def_struct.h:150
ptr_int_list cons ( GENERIC  v,
ptr_int_list  l 
)

cons

Parameters
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.

180 {
181  ptr_int_list n;
182 
183  n=HEAP_ALLOC(int_list);
184  n->value_1=v;
185  n->next=l;
186 
187  return n;
188 }
GENERIC value_1
Definition: def_struct.h:85
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_int_list next
Definition: def_struct.h:86
ptr_int_list copyTypeCode ( ptr_int_list  u)

copyTypeCode

Parameters
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.

809 {
810  ptr_int_list code;
811 
812  code = HEAP_ALLOC(int_list);
813  code->value_1=0;
814  code->next=NULL;
815 
816  or_codes(code, u);
817 
818  return code;
819 }
#define NULL
Definition: def_const.h:533
GENERIC value_1
Definition: def_struct.h:85
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
void or_codes(ptr_int_list u, ptr_int_list v)
or_codes
Definition: types.c:831
ptr_int_list next
Definition: def_struct.h:86
long count_sorts ( long  c0)

count_sorts

Parameters
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.

711 {
712  ptr_definition d;
713 
714  for(d=first_definition;d;d=d->next)
715  if (d->type_def==(def_type)type_it) c0++;
716 
717  return c0;
718 }
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
def_type type_def
Definition: def_struct.h:153
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
ptr_definition next
Definition: def_struct.h:164
ptr_int_list decode ( ptr_int_list  c)

decode

Parameters
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.

1785 {
1786  ptr_int_list c2,c3,c4,result=NULL,*prev;
1787  long p;
1788 
1789  p=bit_length(c);
1790 
1791  while (p) {
1792  p--;
1793  c2=gamma_table[p]->code;
1794  result=cons((GENERIC)gamma_table[p],result);
1795  prev= &c4;
1796  *prev=NULL;
1797 
1798  while (c2) {
1799  c3=STACK_ALLOC(int_list);
1800  *prev=c3;
1801  prev= &(c3->next);
1802  *prev=NULL;
1803 
1804  c3->value_1=(GENERIC)(((unsigned long)(c->value_1)) & ~((unsigned long)(c2->value_1)));
1805 
1806  c=c->next;
1807  c2=c2->next;
1808  }
1809 
1810  c=c4;
1811  p=bit_length(c);
1812  }
1813 
1814  return result;
1815 }
ptr_definition * gamma_table
Definition: types.c:14
ptr_int_list cons(GENERIC v, ptr_int_list l)
cons
Definition: types.c:179
#define NULL
Definition: def_const.h:533
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
long bit_length(ptr_int_list c)
bit_length
Definition: types.c:1753
#define STACK_ALLOC(A)
Definition: def_macro.h:21
ptr_int_list code
Definition: def_struct.h:150
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list next
Definition: def_struct.h:86
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.

1092 {
1093  long p=0,i,possible,ok=TRUE;
1094  ptr_int_list layer,l,kids,dads,code;
1095  ptr_definition xdef,kdef,ddef; //,err;
1096 
1097  if (types_modified) {
1098 
1099  nothing->parents=NULL;
1101 
1102  top->parents=NULL;
1103  top->children=NULL;
1104 
1105  /* The following definitions are vital to avoid crashes */
1107  make_type_link(lf_true,boolean);
1108  make_type_link(lf_false,boolean);
1109 
1110  /* These just might be useful */
1112  make_type_link(boolean,built_in);
1114 
1116 
1117  type_count=count_sorts(-1); /* bottom does not count */
1118  clear_coding();
1119  nothing->parents=NULL; /* Must be cleared before all_sorts */
1120  all_sorts();
1121  if (type_cyclicity(nothing,NULL)) {
1122  clear_coding();
1123  return;
1124  }
1125  clear_coding();
1126  nothing->parents=NULL; /* Must be cleared before least_sorts */
1127  least_sorts();
1128 
1129  nothing->code=NULL;
1130 
1131  /* RM: Feb 17 1993 */
1132  traceline("*** Codes:\n%C= %s\n", NULL, nothing->keyword->symbol);
1133 
1135 
1136  layer=nothing->parents;
1137 
1138  while (layer) {
1139  l=layer;
1140  do {
1141  xdef=(ptr_definition)l->value_1;
1142  if (xdef->code==NOT_CODED && xdef!=top) {
1143 
1144  kids=xdef->children;
1145  code=two_to_the(p);
1146 
1147  while (kids) {
1148  kdef=(ptr_definition)kids->value_1;
1149  or_codes(code,kdef->code);
1150  kids=kids->next;
1151  }
1152 
1153  xdef->code=code;
1154  gamma_table[p]=xdef;
1155 
1156  /* RM: Feb 17 1993 */
1157  traceline("%C = %s\n", code, xdef->keyword->symbol);
1158  p=p+1;
1159  }
1160 
1161  l=l->next;
1162 
1163  } while (l);
1164 
1165  l=layer;
1166  layer=NULL;
1167 
1168  do {
1169  xdef=(ptr_definition)l->value_1;
1170  dads=xdef->parents;
1171 
1172  while (dads) {
1173  ddef=(ptr_definition)dads->value_1;
1174  if(ddef->code==NOT_CODED) {
1175 
1176  possible=TRUE;
1177  kids=ddef->children;
1178 
1179  while(kids && possible) {
1180  kdef=(ptr_definition)kids->value_1;
1181  if(kdef->code==NOT_CODED)
1182  possible=FALSE;
1183  kids=kids->next;
1184  }
1185  if(possible)
1186  layer=cons((GENERIC)ddef,layer);
1187  }
1188  dads=dads->next;
1189  }
1190  l=l->next;
1191  } while(l);
1192  }
1193 
1194  top->code=two_to_the(p);
1195  for (i=0;i<p;i++)
1196  or_codes(top->code,two_to_the(i));
1197 
1198  gamma_table[p]=top;
1199 
1200  /* RM: Jan 13 1993 */
1201  /* Added the following line because type_count is now over generous
1202  because the same definition can be referenced several times in
1203  the symbol table because of modules
1204  */
1205  type_count=p+1;
1206  for(i=type_count;i<type_count;i++)
1207  gamma_table[i]=NULL;
1208 
1209  traceline("%C = @\n\n", top->code);
1210  equalize_codes(p/32+1);
1211 
1213 
1214  /* Inherit 'FALSE' always_check flags to all types' children */
1216 
1217  traceline("*** Encoding done, %d sorts\n",type_count);
1218 
1220  Errorline("the sorts 'real' and 'string' are not disjoint.\n");
1221  ok=FALSE;
1222  }
1223 
1224  /* RM: Dec 15 1992 I don't think this really matters any more
1225  if (overlap_type(real,alist)) {
1226  Errorline("the sorts 'real' and 'list' are not disjoint.\n");
1227  ok=FALSE;
1228  }
1229  */
1230 
1231  /* RM: Dec 15 1992 I don't think this really matters any more
1232  if (overlap_type(alist,quoted_string)) {
1233  Errorline("the sorts 'list' and 'string' are not disjoint.\n");
1234  ok=FALSE;
1235  }
1236  */
1237 
1238  if (!ok) {
1239  perr("*** Internal problem:\n");
1240  perr("*** Wild_Life may behave abnormally because some basic types\n");
1241  perr("*** have been defined incorrectly.\n\n");
1242  }
1243 
1245  types_done=TRUE;
1246  }
1247 }
long type_cyclicity(ptr_definition d, ptr_int_list anc)
type_cyclicity
Definition: types.c:977
ptr_definition * gamma_table
Definition: types.c:14
void least_sorts()
void least_sorts()
Definition: types.c:743
void perr(char *str)
perr
Definition: error.c:763
ptr_definition lf_false
symbol in bi module
Definition: def_glob.h:284
ptr_definition integer
symbol in bi module
Definition: def_glob.h:312
ptr_definition nothing
symbol in bi module
Definition: def_glob.h:347
long type_count
Definition: def_glob.h:1021
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
ptr_int_list two_to_the(long p)
two_to_the
Definition: types.c:776
void propagate_definitions()
propagate_definitions
Definition: types.c:662
void clear_coding()
clear_coding
Definition: types.c:727
long overlap_type(ptr_definition t1, ptr_definition t2)
overlap_type
Definition: types.c:1579
ptr_keyword keyword
Definition: def_struct.h:147
ptr_int_list cons(GENERIC v, ptr_int_list l)
cons
Definition: types.c:179
#define NULL
Definition: def_const.h:533
void make_sys_type_links()
make_sys_type_links
Definition: sys.c:2168
char * symbol
Definition: def_struct.h:118
long types_modified
Definition: def_glob.h:1022
void inherit_always_check()
inherit_always_check
Definition: types.c:1068
ptr_definition built_in
symbol in bi module
Definition: def_glob.h:199
void traceline(char *format,...)
traceline
Definition: error.c:186
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
void make_type_link(ptr_definition t1, ptr_definition t2)
make_type_link
Definition: types.c:901
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
void all_sorts()
all_sorts
Definition: types.c:759
#define FALSE
Standard boolean.
Definition: def_const.h:275
struct wl_definition * ptr_definition
Definition: def_struct.h:59
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
void equalize_codes(int len)
equalize_codes
Definition: types.c:859
long types_done
Definition: def_glob.h:1012
ptr_int_list code
Definition: def_struct.h:150
ptr_definition lf_true
symbol in bi module
Definition: def_glob.h:410
GENERIC value_1
Definition: def_struct.h:85
long count_sorts(long c0)
count_sorts
Definition: types.c:710
ptr_int_list children
Definition: def_struct.h:152
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
GENERIC heap_alloc(long s)
heap_alloc
Definition: memory.c:1616
void or_codes(ptr_int_list u, ptr_int_list v)
or_codes
Definition: types.c:831
ptr_int_list next
Definition: def_struct.h:86
ptr_int_list parents
Definition: def_struct.h:151
void equalize_codes ( int  len)

equalize_codes

Parameters
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.

860 {
861  ptr_definition d;
862  ptr_int_list c,*ci;
863  long i;
864  int w;
865 
866  for(d=first_definition;d;d=d->next)
867  if (d->type_def==(def_type)type_it) {
868  c = d->code;
869  ci = &(d->code); /* RM: Feb 15 1993 */
870  w=len;
871 
872  /* Count how many words have to be added */
873  while (c) {
874  ci= &(c->next);
875  c=c->next;
876  w--;
877  }
878  assert(w>=0);
879  /* Add the words */
880  for (i=0; i<w; i++) {
881  *ci = HEAP_ALLOC(int_list);
882  (*ci)->value_1=0;
883  ci= &((*ci)->next);
884  }
885  (*ci)=NULL;
886  }
887 }
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
def_type type_def
Definition: def_struct.h:153
#define NULL
Definition: def_const.h:533
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
ptr_definition next
Definition: def_struct.h:164
ptr_int_list code
Definition: def_struct.h:150
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
#define assert(N)
Definition: memory.c:114
ptr_int_list next
Definition: def_struct.h:86
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.

551 {
552  ptr_definition d;
553  ptr_int_list l;
554 
555  for(d=first_definition;d;d=d->next)
556  if(d->type_def==(def_type)type_it && d->parents==NULL) {
557  l=HEAP_ALLOC(int_list);
558  l->value_1=(GENERIC)d;
559  l->next=adults;
560  adults=l;
561  }
562 }
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
def_type type_def
Definition: def_struct.h:153
#define NULL
Definition: def_const.h:533
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
ptr_definition next
Definition: def_struct.h:164
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_int_list adults
Definition: def_glob.h:1001
GENERIC value_1
Definition: def_struct.h:85
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_int_list next
Definition: def_struct.h:86
ptr_int_list parents
Definition: def_struct.h:151
long glb ( ptr_definition  t1,
ptr_definition  t2,
ptr_definition t3,
ptr_int_list c3 
)

glb

Parameters
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.

1482 {
1483  ptr_int_list c1,c2;
1484  long result=0;
1485  unsigned long v1,v2,v3;
1486  int e1,e2,b; /* RM: May 7 1993 */
1487 
1488 
1489 
1490  *c3=NULL;
1491 
1492  if (t1==t2) {
1493  result=1;
1494  *t3= t1;
1495  }
1496  else if (t1==top) {
1497  *t3= t2;
1498  if (t2==top)
1499  result=1;
1500  else
1501  result=3;
1502  }
1503  else if (t2==top) {
1504  result=2;
1505  *t3= t1;
1506  }
1507  else {
1508  /* printf("glb of %s and %s\n",
1509  t1->keyword->combined_name,
1510  t2->keyword->combined_name); */
1511 
1512  c1=t1->code;
1513  c2=t2->code;
1514 
1515  e1=TRUE;e2=TRUE;b=TRUE;
1516 
1517  if (c1!=NOT_CODED && c2!=NOT_CODED) {
1518  result=0;
1519  while (c1 && c2) {
1520 
1521  *c3 = STACK_ALLOC(int_list);
1522  (*c3)->next=NULL;
1523 
1524  v1=(unsigned long)(c1->value_1);
1525  v2=(unsigned long)(c2->value_1);
1526  v3=v1 & v2;
1527 
1528  /* printf("v1=%d, v2=%d, v3=%d\n",v1,v2,v3); */
1529 
1530  (*c3)->value_1=(GENERIC)v3;
1531 
1532  if(v3!=v1) /* RM: May 7 1993 */
1533  e1=FALSE;
1534  if(v3!=v2)
1535  e2=FALSE;
1536  if(v3)
1537  b=FALSE;
1538 
1539  c1=c1->next;
1540  c2=c2->next;
1541  c3= &((*c3)->next);
1542  }
1543  *t3=NULL;
1544 
1545  if(b) /* RM: May 7 1993 */
1546  result=0; /* 0 if T3 = bottom */
1547  else
1548  if(e1)
1549  if(e2)
1550  result=1; /* 1 if T1 = T2 */
1551  else
1552  result=2; /* 2 if T1 <| T2 ( T3 = T1 ) */
1553  else
1554  if(e2)
1555  result=3; /* 3 if T1 |> T2 ( T3 = T2 ) */
1556  else
1557  result=4; /* 4 otherwise */
1558  }
1559  }
1560 
1561  if (!result) *t3=nothing;
1562 
1563  /* printf("result=%d\n\n",result); */
1564 
1565  return result;
1566 }
ptr_definition nothing
symbol in bi module
Definition: def_glob.h:347
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
#define NULL
Definition: def_const.h:533
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
#define STACK_ALLOC(A)
Definition: def_macro.h:21
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
ptr_int_list code
Definition: def_struct.h:150
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list next
Definition: def_struct.h:86
long glb_code ( long  f1,
GENERIC  c1,
long  f2,
GENERIC  c2,
long *  f3,
GENERIC c3 
)

glb_code

Parameters
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.

1352 {
1353  long result=0;
1354  unsigned long v1,v2,v3;
1355  ptr_int_list cd1,cd2,*cd3; /* sort codes */
1356 
1357  /* First, the cases where c1 & c2 are ptr_definitions: */
1358  if (f1 && f2) {
1359  if ((ptr_definition)c1==(ptr_definition)c2) {
1360  *c3=c1;
1361  result=1;
1362  }
1363  else if ((ptr_definition)c1==top) {
1364  *c3=c2;
1365  if ((ptr_definition)c2==top)
1366  result=1;
1367  else
1368  result=3;
1369  }
1370  else if ((ptr_definition)c2==top) {
1371  *c3=c1;
1372  result=2;
1373  }
1374  /* If both inputs are either top or the same ptr_definition */
1375  /* then can return quickly with a ptr_definition. */
1376  if (result) {
1377  *f3=TRUE; /* c3 is ptr_definition (an interned symbol) */
1378  return result;
1379  }
1380  }
1381  /* In the other cases, can't return with a ptr_definition: */
1382  cd1=(ptr_int_list)(f1?(GENERIC)((ptr_definition)c1)->code:c1);
1383  cd2=(ptr_int_list)(f2?(GENERIC)((ptr_definition)c2)->code:c2);
1384  cd3=(ptr_int_list*)c3;
1385  *f3=FALSE; /* cd3 is ptr_int_list (a sort code) */
1386  if (cd1==NOT_CODED) {
1387  if (cd2==NOT_CODED) {
1388  if (c1==c2) {
1389  *cd3=cd1;
1390  result=1;
1391  }
1392  else
1393  result=0;
1394  }
1395  else if (cd2==top->code) {
1396  *cd3=cd1;
1397  result=2;
1398  }
1399  else
1400  result=0;
1401  }
1402  else if (cd1==top->code) {
1403  if (cd2==top->code) {
1404  *cd3=cd1;
1405  result=1;
1406  }
1407  else {
1408  *cd3=cd2;
1409  result=3;
1410  }
1411  }
1412  else if (cd2==NOT_CODED)
1413  result=0;
1414  else if (cd2==top->code) {
1415  *cd3=cd1;
1416  result=2;
1417  }
1418  else while (cd1 && cd2) {
1419  /* Bit operations needed only if c1 & c2 coded & different from top */
1420  *cd3 = STACK_ALLOC(int_list);
1421  (*cd3)->next=NULL;
1422 
1423  v1=(unsigned long)(cd1->value_1);
1424  v2=(unsigned long)(cd2->value_1);
1425  v3=v1 & v2;
1426  (*cd3)->value_1=(GENERIC)v3;
1427 
1428  if (v3) {
1429  if (v3<v1 && v3<v2)
1430  result=4;
1431  else if (result!=4)
1432  if (v1<v2)
1433  result=2;
1434  else if (v1>v2)
1435  result=3;
1436  else
1437  result=1;
1438  }
1439  else if (result)
1440  if (v1 || v2)
1441  result=4;
1442 
1443  cd1=cd1->next;
1444  cd2=cd2->next;
1445  cd3= &((*cd3)->next);
1446  }
1447 
1448  return result;
1449 }
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
#define NULL
Definition: def_const.h:533
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
struct wl_definition * ptr_definition
Definition: def_struct.h:59
#define STACK_ALLOC(A)
Definition: def_macro.h:21
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
ptr_int_list code
Definition: def_struct.h:150
GENERIC value_1
Definition: def_struct.h:85
struct wl_int_list * ptr_int_list
Definition: def_struct.h:57
ptr_int_list next
Definition: def_struct.h:86
long glb_value ( long  result,
long  f,
GENERIC  c,
GENERIC  value1,
GENERIC  value2,
GENERIC value 
)

glb_value

Parameters
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.

1291 {
1292  ptr_int_list code;
1293 
1294  if (!result) return FALSE;
1295  if (value1==NULL) {
1296  *value=value2;
1297  return TRUE;
1298  }
1299  if (value2==NULL) {
1300  *value=value1;
1301  return TRUE;
1302  }
1303  /* At this point, both value fields are non-NULL */
1304  /* and must be compared. */
1305 
1306  /* Get a pointer to the sort code */
1307  code = f ? ((ptr_definition)c)->code : (ptr_int_list)c;
1308 
1309  /* This rather time-consuming analysis is necessary if both objects */
1310  /* have non-NULL value fields. Note that only those objects with a */
1311  /* non-NULL value field needed for disentailment are looked at. */
1312  if (sub_CodeType(code,real->code)) {
1313  *value=value1;
1314  return (*(REAL *)value1 == *(REAL *)value2);
1315  }
1316  else if (sub_CodeType(code,quoted_string->code)) {
1317  *value=value1;
1318  return (!strcmp((char *)value1,(char *)value2));
1319  }
1320  else {
1321  /* All other sorts with 'value' fields always return TRUE, that is, */
1322  /* the value field plays no role in disentailment. */
1323  *value=value1;
1324  return TRUE;
1325  }
1326 }
long sub_CodeType(ptr_int_list c1, ptr_int_list c2)
sub_CodeType
Definition: types.c:1618
#define NULL
Definition: def_const.h:533
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
struct wl_definition * ptr_definition
Definition: def_struct.h:59
ptr_int_list code
Definition: def_struct.h:150
struct wl_int_list * ptr_int_list
Definition: def_struct.h:57
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
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().

1069 {
1070  long change;
1071 
1072  do {
1073  change=FALSE;
1074  one_pass_always_check(&change);
1075  } while (change);
1076 }
void one_pass_always_check(long *ch)
one_pass_always_check
Definition: types.c:1049
#define FALSE
Standard boolean.
Definition: def_const.h:275
void insert_own_prop ( ptr_definition  d)

insert_own_prop

Parameters
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.

576 {
577  ptr_int_list l;
578  ptr_pair_list rule;
579  ptr_triple_list *t;
580  long flag;
581 
582  l=HEAP_ALLOC(int_list);
583  l->value_1=(GENERIC)d;
584  l->next=children;
585  children=l;
586 
587  rule = d->rule;
588  while (rule) {
589  t= &(d->properties);
590  flag=TRUE;
591 
592  while (flag) {
593  if (*t)
594  if ((*t)->aaaa_4==rule->aaaa_2 && (*t)->bbbb_4==rule->bbbb_2 && (*t)->cccc_4==d)
595  flag=FALSE;
596  else
597  t= &((*t)->next);
598  else {
599  *t = HEAP_ALLOC(triple_list);
600  (*t)->aaaa_4=rule->aaaa_2;
601  (*t)->bbbb_4=rule->bbbb_2;
602  (*t)->cccc_4=d;
603  (*t)->next=NULL;
604  flag=FALSE;
605  }
606  }
607  rule=rule->next;
608  }
609 }
ptr_psi_term aaaa_2
Definition: def_struct.h:205
ptr_pair_list next
Definition: def_struct.h:207
#define NULL
Definition: def_const.h:533
ptr_definition next
Definition: def_struct.h:164
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_pair_list rule
Definition: def_struct.h:148
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_psi_term bbbb_2
Definition: def_struct.h:206
ptr_int_list children
Definition: def_glob.h:1001
GENERIC value_1
Definition: def_struct.h:85
ptr_triple_list properties
Definition: def_struct.h:149
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_int_list next
Definition: def_struct.h:86
void insert_prop ( ptr_definition  d,
ptr_triple_list  prop 
)

insert_prop

Parameters
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.

621 {
622  ptr_int_list l;
623  ptr_triple_list *t;
624  long flag;
625 
626  l=HEAP_ALLOC(int_list);
627  l->value_1=(GENERIC)d;
628  l->next=children;
629  children=l;
630 
631  while (prop) {
632  t= &(d->properties);
633  flag=TRUE;
634 
635  while (flag) {
636  if (*t)
637  if ((*t)->aaaa_4==prop->aaaa_4 && (*t)->bbbb_4==prop->bbbb_4 && (*t)->cccc_4==prop->cccc_4)
638  flag=FALSE;
639  else
640  t= &((*t)->next);
641  else {
642  *t = HEAP_ALLOC(triple_list);
643  (*t)->aaaa_4=prop->aaaa_4;
644  (*t)->bbbb_4=prop->bbbb_4;
645  (*t)->cccc_4=prop->cccc_4;
646  (*t)->next=NULL;
647  flag=FALSE;
648  }
649  }
650  prop=prop->next;
651  }
652 }
#define NULL
Definition: def_const.h:533
ptr_triple_list next
Definition: def_struct.h:215
ptr_definition cccc_4
Definition: def_struct.h:214
ptr_definition next
Definition: def_struct.h:164
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_psi_term bbbb_4
Definition: def_struct.h:213
ptr_int_list children
Definition: def_glob.h:1001
GENERIC value_1
Definition: def_struct.h:85
ptr_triple_list properties
Definition: def_struct.h:149
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_psi_term aaaa_4
Definition: def_struct.h:212
ptr_int_list next
Definition: def_struct.h:86
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.

744 {
745  ptr_definition d;
746 
747  for(d=first_definition;d;d=d->next)
748  if (d->type_def==(def_type)type_it && d->children==NULL && d!=nothing)
750 }
ptr_definition nothing
symbol in bi module
Definition: def_glob.h:347
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
def_type type_def
Definition: def_struct.h:153
ptr_int_list cons(GENERIC v, ptr_int_list l)
cons
Definition: types.c:179
#define NULL
Definition: def_const.h:533
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
ptr_definition next
Definition: def_struct.h:164
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_int_list children
Definition: def_struct.h:152
ptr_int_list parents
Definition: def_struct.h:151
void make_type_link ( ptr_definition  t1,
ptr_definition  t2 
)

make_type_link

Parameters
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().

902 {
903  if (t2!=top && !type_member(t2,t1->parents))
904  t1->parents=cons((GENERIC)t2,t1->parents);
905  if (t2!=top && !type_member(t1,t2->children))
906  t2->children=cons((GENERIC)t1,t2->children);
907 }
ptr_int_list cons(GENERIC v, ptr_int_list l)
cons
Definition: types.c:179
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
ptr_int_list children
Definition: def_struct.h:152
long type_member(ptr_definition t, ptr_int_list tlst)
type_member
Definition: types.c:918
ptr_int_list parents
Definition: def_struct.h:151
long matches ( ptr_definition  t1,
ptr_definition  t2,
long *  smaller 
)

matches

Parameters
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.

1667 {
1668  ptr_int_list c1,c2;
1669  long result=TRUE;
1670 
1671  *smaller=TRUE;
1672 
1673  if (t1!=t2)
1674  if (t2!=top)
1675  if (t1==top)
1676  *smaller=FALSE;
1677  else {
1678  c1=t1->code;
1679  c2=t2->code;
1680  result=FALSE;
1681 
1682  if (c1!=NOT_CODED && c2!=NOT_CODED) {
1683  while (c1 && c2) {
1684  if ((unsigned long)c1->value_1 & (unsigned long)c2->value_1) result=TRUE;
1685  if ((unsigned long)c1->value_1 & ~(unsigned long)c2->value_1) *smaller=FALSE;
1686  c1=c1->next;
1687  c2=c2->next;
1688  }
1689  }
1690  else
1691  *smaller=FALSE;
1692  }
1693 
1694  return result;
1695 }
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
ptr_int_list code
Definition: def_struct.h:150
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list next
Definition: def_struct.h:86
void one_pass_always_check ( long *  ch)

one_pass_always_check

Parameters
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.

1050 {
1051  ptr_definition d;
1052 
1053 
1054  for(d=first_definition;d;d=d->next)
1055  if (d->type_def==(def_type)type_it && !d->always_check)
1056  propagate_always_check(d,ch);
1057 }
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
def_type type_def
Definition: def_struct.h:153
char always_check
Definition: def_struct.h:154
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
ptr_definition next
Definition: def_struct.h:164
void propagate_always_check(ptr_definition d, long *ch)
propagate_always_check
Definition: types.c:1022
void or_codes ( ptr_int_list  u,
ptr_int_list  v 
)

or_codes

Parameters
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.

832 {
833  while (v) {
834  u->value_1= (GENERIC)(((unsigned long)(u->value_1)) | ((unsigned long)(v->value_1)));
835  v=v->next;
836  if (u->next==NULL && v) {
838  u=u->next;
839  u->value_1=0;
840  u->next=NULL;
841  }
842  else
843  u=u->next;
844  }
845 }
#define NULL
Definition: def_const.h:533
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
GENERIC value_1
Definition: def_struct.h:85
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_int_list next
Definition: def_struct.h:86
long overlap_type ( ptr_definition  t1,
ptr_definition  t2 
)

overlap_type

Parameters
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.

1580 {
1581  ptr_int_list c1,c2;
1582  long result=TRUE;
1583 
1584  if (t1!=t2 && t1!=top && t2!=top) {
1585 
1586  c1=t1->code;
1587  c2=t2->code;
1588  result=FALSE;
1589 
1590  if (c1!=NOT_CODED && c2!=NOT_CODED) {
1591  while (!result && c1 && c2) {
1592  result=(((unsigned long)(c1->value_1)) & ((unsigned long)(c2->value_1)));
1593  c1=c1->next;
1594  c2=c2->next;
1595  }
1596  }
1597  }
1598 
1599  /*
1600  printf("overlap_type(%s,%s) => %ld\n",t1->def->keyword->symbol,t2->def->keyword->symbol,result);
1601  */
1602 
1603  return result;
1604 }
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
ptr_int_list code
Definition: def_struct.h:150
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list next
Definition: def_struct.h:86
void perr_sort ( ptr_definition  d)

perr_sort

Parameters
d- ptr_definition d

Definition at line 933 of file types.c.

References wl_definition::keyword, perr_s(), and wl_keyword::symbol.

934 {
935  perr_s("%s",d->keyword->symbol);
936 }
ptr_keyword keyword
Definition: def_struct.h:147
void perr_s(char *s1, char *s2)
perr_s
Definition: error.c:775
char * symbol
Definition: def_struct.h:118
void perr_sort_cycle ( ptr_int_list  anc)

perr_sort_cycle

Parameters
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.

960 {
962  perr(" <| ");
963  perr_sort_list(anc);
964 }
void perr(char *str)
perr
Definition: error.c:763
void perr_sort_list(ptr_int_list anc)
perr_sort_list
Definition: types.c:944
void perr_sort(ptr_definition d)
perr_sort
Definition: types.c:933
GENERIC value_1
Definition: def_struct.h:85
void perr_sort_list ( ptr_int_list  anc)

perr_sort_list

Parameters
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.

945 {
946  if (anc) {
947  perr_sort_list(anc->next);
948  if (anc->next) perr(" <| ");
950  }
951 }
void perr(char *str)
perr
Definition: error.c:763
void perr_sort_list(ptr_int_list anc)
perr_sort_list
Definition: types.c:944
void perr_sort(ptr_definition d)
perr_sort
Definition: types.c:933
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list next
Definition: def_struct.h:86
void print_codes ( )

print_codes

PRINT_CODES() Print all the codes.

Definition at line 1256 of file types.c.

References outputline(), and type_count.

1257 {
1258  long i;
1259 
1260  for (i=0; i<type_count; i++) {
1261  outputline("%C = %s\n",
1262  gamma_table[i]->code,
1263  gamma_table[i]->keyword->combined_name);
1264  }
1265 }
ptr_definition * gamma_table
Definition: types.c:14
long type_count
Definition: def_glob.h:1021
void outputline(char *format,...)
void outputline(char *format,...)
Definition: error.c:101
void print_def_type ( def_type  t)

print_def_type

Parameters
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.

25 {
26  switch ((long)t) {
27  case (long)predicate_it:
28  perr("predicate");
29  break;
30  case (long)function_it:
31  perr("function");
32  break;
33  case (long)type_it:
34  perr("sort");
35  break;
36  case (long)global_it: /* RM: Feb 8 1993 */
37  perr("global variable");
38  break;
39  default:
40  perr("undefined");
41  }
42 }
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
void perr(char *str)
perr
Definition: error.c:763
#define predicate_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1401
#define global_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1422
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
void propagate_always_check ( ptr_definition  d,
long *  ch 
)

propagate_always_check

Parameters
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.

1023 {
1024  ptr_int_list child_list;
1025  ptr_definition child;
1026 
1027  child_list = d->children;
1028  while (child_list) {
1029  child = (ptr_definition)child_list->value_1;
1030  if (child->always_check) {
1031  child->always_check = FALSE;
1032  *ch = TRUE;
1033  propagate_always_check(child,ch);
1034  }
1035  child_list = child_list->next;
1036  }
1037 }
char always_check
Definition: def_struct.h:154
#define TRUE
Standard boolean.
Definition: def_const.h:268
void propagate_always_check(ptr_definition d, long *ch)
propagate_always_check
Definition: types.c:1022
#define FALSE
Standard boolean.
Definition: def_const.h:275
struct wl_definition * ptr_definition
Definition: def_struct.h:59
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list children
Definition: def_struct.h:152
ptr_int_list next
Definition: def_struct.h:86
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.

663 {
664  ptr_int_list kids;
665  ptr_definition d;
666 
667  adults=NULL;
668  find_adults();
669 
670  while (adults) {
671 
672  children=NULL;
673 
674  while (adults) {
676 
677  insert_own_prop(d);
679 
680  kids=d->children;
681 
682  while(kids) {
684  /* if (d->always_check && kids->value_1)
685  ((ptr_definition)kids->value_1)->always_check=TRUE; */
686  kids=kids->next;
687  }
688  adults=adults->next;
689  }
691  }
692 }
void find_adults()
find_adults
Definition: types.c:549
#define NULL
Definition: def_const.h:533
void insert_prop(ptr_definition d, ptr_triple_list prop)
insert_prop
Definition: types.c:620
struct wl_definition * ptr_definition
Definition: def_struct.h:59
void insert_own_prop(ptr_definition d)
insert_own_prop
Definition: types.c:575
ptr_int_list children
Definition: def_glob.h:1001
ptr_int_list adults
Definition: def_glob.h:1001
GENERIC value_1
Definition: def_struct.h:85
ptr_triple_list properties
Definition: def_struct.h:149
ptr_int_list children
Definition: def_struct.h:152
ptr_int_list next
Definition: def_struct.h:86
long redefine ( ptr_psi_term  t)

redefine

Parameters
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().

105 {
106  ptr_definition d; // ,d2;
107  // ptr_int_list l,*l2;
108  long success=TRUE;
109 
110  deref_ptr(t);
111  d=t->type;
112  if (d->date<file_date) {
113  if (d->type_def==(def_type)type_it) {
114  /* Except for top, sorts are always unprotected, with a warning. */
115  if (FALSE /*d==top*/) {
116  Errorline("the top sort '@' may not be extended.\n");
117  success=FALSE;
118  }
119  /* RM: Mar 25 1993
120  else if (d!=top)
121  warningline("extending definition of sort '%s'.\n",d->keyword->symbol);
122  */
123  }
124  else if (d->protected && d->type_def!=(def_type)undef_it) {
125  if (d->date>0) {
126  /* The term was entered in a previous file, and therefore */
127  /* cannot be altered. */
128  Errorline("the %T '%s' may not be changed.\n", /* RM: Jan 27 1993 */
129  d->type_def, d->keyword->combined_name);
130  success=FALSE;
131  }
132  else {
133  if (d->rule && (unsigned long)d->rule<=MAX_BUILT_INS /*&& input_stream==stdin*/) {
134  /* d is a built-in, and therefore cannot be altered. */
135  Errorline("the built-in %T '%s' may not be extended.\n",
136  d->type_def, d->keyword->symbol);
137  success=FALSE;
138  }
139  else {
140  /* d is not a built-in, and therefore can be altered. */
141  warningline("extending the %T '%s'.\n",d->type_def,d->keyword->symbol);
142  if (warningflag) if (!yes_or_no()) success=FALSE;
143  }
144  }
145  }
146 
147  if (success) {
148  if (d->type_def==(def_type)type_it) { /* d is an already existing type */
149  /* Remove cycles in the type hierarchy of d */
150  /* This is done by Richard's version, and I don't know why. */
151  /* It seems to be a no-op. */
152  remove_cycles(d, &(d->children));
153  remove_cycles(d, &(d->parents));
154  /* d->rule=NULL; */ /* Types must keep their rules! */
155  /* d->properties=NULL; */ /* Types get new properties from encode */
156  }
157  if (d->date==0) d->date=file_date;
158  /* d->type=undef_it; */ /* Objects keep their type! */
159  /* d->always_check=TRUE; */
160  /* d->protected=TRUE; */
161  /* d->children=NULL; */
162  /* d->parents=NULL; */
163  /* d->code=NOT_CODED; */
164  }
165  }
166 
167  return success;
168 }
#define undef_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1394
char * combined_name
Definition: def_struct.h:119
def_type type_def
Definition: def_struct.h:153
long file_date
Definition: def_glob.h:1034
ptr_keyword keyword
Definition: def_struct.h:147
void remove_cycles(ptr_definition d, ptr_int_list *dl)
remove_cycles
Definition: types.c:85
long warningflag
Definition: def_glob.h:911
char * symbol
Definition: def_struct.h:118
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_pair_list rule
Definition: def_struct.h:148
#define FALSE
Standard boolean.
Definition: def_const.h:275
#define MAX_BUILT_INS
Maximum number of built_ins.
Definition: def_const.h:154
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
ptr_int_list children
Definition: def_struct.h:152
long yes_or_no()
yes_or_no
Definition: types.c:50
ptr_int_list parents
Definition: def_struct.h:151
void remove_cycles ( ptr_definition  d,
ptr_int_list dl 
)

remove_cycles

Parameters
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.

86 {
87  while (*dl) {
88  if (((ptr_definition)(*dl)->value_1)==d)
89  *dl = (*dl)->next;
90  else
91  dl= &((*dl)->next);
92  }
93 }
ptr_int_list next
Definition: def_struct.h:86
long strict_matches ( ptr_psi_term  t1,
ptr_psi_term  t2,
long *  smaller 
)

strict_matches

Parameters
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.

1714 {
1715  long result,sm;
1716 
1717  result=matches(t1->type,t2->type,&sm);
1718 
1719  if (sm) {
1720  /* At this point, t1->type <| t2->type */
1721  if (t1->type==t2->type) {
1722  /* Same types: strict only if first has a value & second does not */
1723  if (t1->value_3!=NULL && t2->value_3==NULL)
1724  sm=TRUE;
1725  else
1726  sm=FALSE;
1727  }
1728  else {
1729  /* Different types: the first must be strictly smaller */
1730  sm=TRUE;
1731  }
1732  }
1733 
1734  *smaller=sm;
1735  return result;
1736 }
#define NULL
Definition: def_const.h:533
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC value_3
Definition: def_struct.h:186
ptr_definition type
Definition: def_struct.h:181
long matches(ptr_definition t1, ptr_definition t2, long *smaller)
matches
Definition: types.c:1666
long sub_CodeType ( ptr_int_list  c1,
ptr_int_list  c2 
)

sub_CodeType

Parameters
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.

1619 {
1620  if (c1!=NOT_CODED && c2!=NOT_CODED) {
1621  while (c1 && c2) {
1622  if ((unsigned long)c1->value_1 & ~(unsigned long)c2->value_1) return FALSE;
1623  c1=c1->next;
1624  c2=c2->next;
1625  }
1626  }
1627  else
1628  return FALSE;
1629 
1630  return TRUE;
1631 }
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list next
Definition: def_struct.h:86
long sub_type ( ptr_definition  t1,
ptr_definition  t2 
)

sub_type

Parameters
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.

1643 {
1644  if (t1!=t2)
1645  if (t2!=top)
1646  {
1647  if (t1==top)
1648  return FALSE;
1649  else
1650  return sub_CodeType(t1->code, t2->code);
1651  }
1652  return TRUE;
1653 }
long sub_CodeType(ptr_int_list c1, ptr_int_list c2)
sub_CodeType
Definition: types.c:1618
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
ptr_int_list code
Definition: def_struct.h:150
ptr_int_list two_to_the ( long  p)

two_to_the

Parameters
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.

777 {
778  ptr_int_list result,code;
779  long v=1;
780 
781  code=HEAP_ALLOC(int_list);
782  code->value_1=0;
783  code->next=NULL;
784  result=code;
785 
786  while (p>=INT_SIZE) {
787  code->next=HEAP_ALLOC(int_list);
788  code=code->next;
789  code->value_1=0;
790  code->next=NULL;
791  p=p-INT_SIZE;
792  }
793 
794  v= v<<p ;
795  code->value_1=(GENERIC)v;
796 
797  return result;
798 }
#define INT_SIZE
How many types can be encoded on one integer in the transitive closure encoding.
Definition: def_const.h:317
#define NULL
Definition: def_const.h:533
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
GENERIC value_1
Definition: def_struct.h:85
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_int_list next
Definition: def_struct.h:86
long type_cyclicity ( ptr_definition  d,
ptr_int_list  anc 
)

type_cyclicity

Parameters
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.

978 {
979  ptr_int_list p=d->parents;
980  ptr_definition pd;
981  long errflag;
982  int_list anc2;
983 
984  while (p) {
985  pd=(ptr_definition)p->value_1;
986  /* If unmarked, mark and recurse */
987  if (pd->code==NOT_CODED) {
988  pd->code = (ptr_int_list)TRUE;
989  anc2.value_1=(GENERIC)pd;
990  anc2.next=anc;
991  errflag=type_cyclicity(pd,&anc2);
992  if (errflag) return TRUE;
993  }
994  /* If marked, check if it's in the ancestor list */
995  else {
996  if (type_member(pd,anc)) {
997  Errorline("there is a cycle in the sort hierarchy\n");
998  perr("*** Cycle: [");
999  perr_sort_cycle(anc);
1000  perr("]\n");
1001  exit_life(TRUE);
1002  return TRUE;
1003  }
1004  }
1005  p=p->next;
1006  }
1007  return FALSE;
1008 }
long type_cyclicity(ptr_definition d, ptr_int_list anc)
type_cyclicity
Definition: types.c:977
void perr(char *str)
perr
Definition: error.c:763
void exit_life(long nl_flag)
exit_life
Definition: built_ins.c:2219
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
void perr_sort_cycle(ptr_int_list anc)
perr_sort_cycle
Definition: types.c:959
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
struct wl_definition * ptr_definition
Definition: def_struct.h:59
ptr_int_list code
Definition: def_struct.h:150
GENERIC value_1
Definition: def_struct.h:85
struct wl_int_list * ptr_int_list
Definition: def_struct.h:57
long type_member(ptr_definition t, ptr_int_list tlst)
type_member
Definition: types.c:918
ptr_int_list next
Definition: def_struct.h:86
ptr_int_list parents
Definition: def_struct.h:151
long type_member ( ptr_definition  t,
ptr_int_list  tlst 
)

type_member

Parameters
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.

919 {
920  while (tlst) {
921  if (t==(ptr_definition)tlst->value_1) return TRUE;
922  tlst=tlst->next;
923  }
924  return FALSE;
925 }
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list next
Definition: def_struct.h:86
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().

51 {
52  char *old_prompt;
53  long c,d;
54  ptr_psi_term old_state_loc;
55 
56  perr("*** Are you really sure you want to do that ");
57  old_prompt=prompt;
58  prompt="(y/n)?";
59  old_state_loc=input_state;
60  (void)open_input_file("stdin");
61 
62  do {
63  do {
64  c=read_char();
65  } while (c!=EOLN && c>0 && c<=32);
66  } while (c!='y' && c!='n');
67 
68  d=c;
69  while (d!=EOLN && d!=EOF) d=read_char();
70 
71  prompt=old_prompt;
72  input_state=old_state_loc;
73  restore_state(old_state_loc);
74  return (c=='y');
75 }
void perr(char *str)
perr
Definition: error.c:763
ptr_psi_term input_state
Definition: def_glob.h:856
#define EOLN
End of line.
Definition: def_const.h:309
void restore_state(ptr_psi_term t)
restore_state
Definition: token.c:334
char * prompt
Definition: def_glob.h:1018
long read_char()
read_char
Definition: token.c:680
long open_input_file(char *file)
open_input_file
Definition: token.c:594

Variable Documentation

ptr_definition* gamma_table = NULL

Definition at line 14 of file types.c.