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

least upper bound of the root sorts of two psi terms More...

Go to the source code of this file.

Functions

ptr_int_list appendIntList (ptr_int_list tail, ptr_int_list more)
 appendIntList More...
 
void mark_ancestors (ptr_definition def, long *flags)
 mark_ancestors More...
 
static long bfs (ptr_definition p, ptr_int_list ans, ptr_int_list pattern, long *flags)
 bfs More...
 
static ptr_int_list makeUnitList (ptr_definition x)
 makeUnitList More...
 
ptr_int_list lub (ptr_psi_term a, ptr_psi_term b, ptr_psi_term *pp)
 

Detailed Description

least upper bound of the root sorts of two psi terms

lub.c - find least upper bound of the root sorts of two psi terms

Definition in file lub.c.

Function Documentation

ptr_int_list appendIntList ( ptr_int_list  tail,
ptr_int_list  more 
)

appendIntList

Parameters
tail- ptr_int_list tail
more- ptr_int_list more

attach copies of more to tail

Definition at line 40 of file lub.c.

References wl_int_list::next, NULL, STACK_ALLOC, and wl_int_list::value_1.

41 {
42  while (more)
43  {
44  tail->next = STACK_ALLOC(int_list);
45  tail= tail->next;
46  tail->value_1 = more->value_1;
47  tail->next = NULL;
48  more = more->next;
49  }
50  return tail;
51 }
#define NULL
Definition: def_const.h:533
#define STACK_ALLOC(A)
Definition: def_macro.h:21
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list next
Definition: def_struct.h:86
static long bfs ( ptr_definition  p,
ptr_int_list  ans,
ptr_int_list  pattern,
long *  flags 
)
static

bfs

Parameters
p- ptr_definition p
ans- ptr_int_list ans
pattern- ptr_int_list pattern
flags- long *flags)

Definition at line 88 of file lub.c.

References appendIntList(), assert, bit_length(), built_in, mark_ancestors(), wl_int_list::next, NULL, or_codes(), wl_definition::parents, STACK_ALLOC, sub_CodeType(), top, and wl_int_list::value_1.

89 {
91  ptr_int_list tail;
92  ptr_int_list par;
93  long len;
94  long found = 0;
95 
96  if (p == top)
97  {
99  return 0; // ADDED 0 DJD 2.05
100  }
101 
102  /* print_code(pattern);*/
103  /* printf("\n");*/
104 
105  par = p->parents;
106  if (par == NULL)
107  return 0; /* only parent is top */
108 
109  assert(par->value_1 != NULL);
110 
111  head->value_1 = par->value_1;
112  head->next = NULL;
113  par = par->next;
114  tail = appendIntList(head, par);
115 
116  while (head)
117  {
118  /* pc(head->value);*/
119  len = bit_length(((ptr_definition )head->value_1)->code);
120  if (!flags[len])
121  {
122  /* we havn't checked this type before */
123 
124  if (!((ptr_definition )head->value_1 == top) &&
125  !((ptr_definition )head->value_1 == built_in) &&
126  (sub_CodeType(pattern,((ptr_definition)head->value_1)->code)))
127  {
128  or_codes(ans, ((ptr_definition)head->value_1)->code);
129  /* print_code(ans);*/
130  /* printf("ans\n");*/
131  found++;
132  /* must set flags of ALL ancestors of head! */
133  mark_ancestors((ptr_definition)head->value_1,flags);
134  }
135  else
136  tail = appendIntList(tail,
137  ((ptr_definition )head->value_1)->parents);
138  flags[len] = 1;
139  }
140  head = head->next;
141  }
142  return found;
143 }
long bit_length(ptr_int_list c)
bit_length
Definition: types.c:1753
void or_codes(ptr_int_list u, ptr_int_list v)
or_codes
Definition: types.c:831
ptr_int_list appendIntList(ptr_int_list tail, ptr_int_list more)
appendIntList
Definition: lub.c:40
#define NULL
Definition: def_const.h:533
void mark_ancestors(ptr_definition def, long *flags)
mark_ancestors
Definition: lub.c:60
ptr_definition built_in
symbol in bi module
Definition: def_glob.h:199
#define STACK_ALLOC(A)
Definition: def_macro.h:21
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
long sub_CodeType(ptr_int_list c1, ptr_int_list c2)
sub_CodeType
Definition: types.c:1618
GENERIC value_1
Definition: def_struct.h:85
#define assert(N)
Definition: memory.c:114
ptr_int_list next
Definition: def_struct.h:86
ptr_int_list parents
Definition: def_struct.h:151
ptr_int_list lub ( ptr_psi_term  a,
ptr_psi_term  b,
ptr_psi_term pp 
)

Definition at line 173 of file lub.c.

References bfs(), wl_definition::code, copyTypeCode(), decode(), isSubTypeValue(), isValue(), makeUnitList(), NULL, or_codes(), stack_alloc(), sub_type(), top, wl_psi_term::type, and type_count.

174 {
175  ptr_definition ta; /* type of psi term a */
176  ptr_definition tb; /* type of psi term b */
177  long *flags; /* set to 1 if this type has been checked in
178  * the lub search.
179  */
180  ptr_int_list ans;
181  ptr_int_list pattern;
182  long found;
183 
184  ta = a->type;
185  tb = b->type;
186 
187  /* special cases first */
188 
189  if (isValue(a) && isValue(b) && sub_type(ta,tb) && sub_type(tb,ta))
190  {
191  /* special case of two values being of same type. Check that they
192  * might actually be same value before returning the type
193  */
194  if (isSubTypeValue(a, b))
195  {
196  /* since we alreadyuu know they are both values, isSubTypeValue
197  * returns TRUE if they are same value, else false
198  */
199 
200  *pp = a;
201  return NULL;
202  }
203  }
204 
205  if (sub_type(ta, tb)) return makeUnitList(tb);
206  if (sub_type(tb, ta)) return makeUnitList(ta);
207 
208  /* ta has the lub of tb&ta without the high bit set, search upwards for a
209  * type that has the same lower bits as ta
210  */
211 
212  /* get the pattern to search for */
213 
214  pattern = copyTypeCode(ta->code);
215  or_codes(pattern, tb->code); /* pattern to search for */
216  ans = copyTypeCode(pattern); /* resulting pattern */
217 
218  /* initialize the table to be non-searched */
219 
220  flags = (long *)stack_alloc(sizeof(unsigned long) * type_count);
221  memset(flags, 0, sizeof(unsigned long) * type_count);
222 
223  /* now do a breadth first search for each of arg1 and arg2 */
224 
225  found = bfs(ta, ans, pattern, flags);
226  found += bfs(tb, ans, pattern, flags);
227 
228  if (found)
229  ans = decode(ans);
230  else
231  ans = makeUnitList(top);
232 
233  return ans;
234 }
int isSubTypeValue(ptr_psi_term arg1, ptr_psi_term arg2)
isSubTypeValue
Definition: bi_type.c:180
long type_count
Definition: def_glob.h:1021
ptr_int_list decode(ptr_int_list c)
decode
Definition: types.c:1784
static long bfs(ptr_definition p, ptr_int_list ans, ptr_int_list pattern, long *flags)
bfs
Definition: lub.c:88
void or_codes(ptr_int_list u, ptr_int_list v)
or_codes
Definition: types.c:831
#define NULL
Definition: def_const.h:533
long sub_type(ptr_definition t1, ptr_definition t2)
sub_type
Definition: types.c:1642
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
ptr_int_list copyTypeCode(ptr_int_list u)
copyTypeCode
Definition: types.c:808
ptr_int_list code
Definition: def_struct.h:150
long isValue(ptr_psi_term p)
isValue(p)
Definition: bi_type.c:694
ptr_definition type
Definition: def_struct.h:181
static ptr_int_list makeUnitList(ptr_definition x)
makeUnitList
Definition: lub.c:152
GENERIC stack_alloc(long s)
stack_alloc
Definition: memory.c:1642
static ptr_int_list makeUnitList ( ptr_definition  x)
static

makeUnitList

Parameters
x- ptr_definition x

make a decoded type list from one type

Definition at line 152 of file lub.c.

References wl_int_list::next, NULL, STACK_ALLOC, and wl_int_list::value_1.

153 {
154  ptr_int_list ans;
155 
156  ans = STACK_ALLOC(int_list);
157  ans->value_1 = (GENERIC )x;
158  ans->next = NULL;
159  return ans;
160 }
#define NULL
Definition: def_const.h:533
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define STACK_ALLOC(A)
Definition: def_macro.h:21
GENERIC value_1
Definition: def_struct.h:85
ptr_int_list next
Definition: def_struct.h:86
void mark_ancestors ( ptr_definition  def,
long *  flags 
)

mark_ancestors

Parameters
def- ptr_definition def
flags- long *flags

Set flags bit for all ancestors (i.e., higher up) of head

Definition at line 60 of file lub.c.

References bit_length(), wl_definition::code, wl_int_list::next, wl_definition::parents, and wl_int_list::value_1.

61 {
62  ptr_int_list par;
63 
64  par=def->parents;
65  while (par) {
67  long len;
68 
69  p=(ptr_definition)par->value_1;
70  len=bit_length(p->code);
71  if (!flags[len]) {
72  flags[len]=1;
73  mark_ancestors(p, flags);
74  }
75  par=par->next;
76  }
77 }
long bit_length(ptr_int_list c)
bit_length
Definition: types.c:1753
void mark_ancestors(ptr_definition def, long *flags)
mark_ancestors
Definition: lub.c:60
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
ptr_int_list next
Definition: def_struct.h:86
ptr_int_list parents
Definition: def_struct.h:151