Wild Life: lub.c File Reference

Wild Life 2.29

- Main Page
- Data Structures
- Files

- File List
- Globals

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

Go to the source code of this file.

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

## Function Documentation

ptr_int_list appendIntList | ( | ptr_int_list | tail,
|  | ptr_int_list | more
| ) |  |

Definition at line 28 of file lub.c.

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

31 {
32 while (more)
33 {
34 tail->next = STACK_ALLOC(int_list);
35 tail= tail->next;
36 tail->value_1 = more->value_1;
37 tail->next = NULL;
38 more = more->next;
39 }
40 return tail;
41 }
NULL
#define NULL
Definition: def_const.h:203
wl_int_list
Definition: def_struct.h:53
STACK_ALLOC
#define STACK_ALLOC(A)
Definition: def_macro.h:16
wl_int_list::value_1
GENERIC value_1
Definition: def_struct.h:54
wl_int_list::next
ptr_int_list next
Definition: def_struct.h:55

static long bfs | ( | ptr_definition | p,
|  | ptr_int_list | ans,
|  | ptr_int_list | pattern,
|  | long * | flags
| ) |  |
| static

Definition at line 66 of file lub.c.

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

71 {
72 ptr_int_list head = STACK_ALLOC(int_list);
73 ptr_int_list tail;
74 ptr_int_list par;
75 long len;
76 long found = 0;
77
78 if (p == top)
79 {
80 or_codes((ptr_int_list)ans, (ptr_int_list)top);
81 return 0; // ADDED 0 DJD 2.05
82 }
83
84 /* print_code(pattern);*/
85 /* printf("\n");*/
86
87 par = p->parents;
88 if (par == NULL)
89 return 0; /* only parent is top */
90
91 assert(par->value_1 != NULL);
92
93 head->value_1 = par->value_1;
94 head->next = NULL;
95 par = par->next;
96 tail = appendIntList(head, par);
97
98 while (head)
99 {
100 /* pc(head->value);*/
101 len = bit_length(((ptr_definition )head->value_1)->code);
102 if (!flags[len])
103 {
104 /* we havn't checked this type before */
105
106 if (!((ptr_definition )head->value_1 == top) &&
107 !((ptr_definition )head->value_1 == built_in) &&
108 (sub_CodeType(pattern,((ptr_definition)head->value_1)->code)))
109 {
110 or_codes(ans, ((ptr_definition)head->value_1)->code);
111 /* print_code(ans);*/
112 /* printf("ans\n");*/
113 found++;
114 /* must set flags of ALL ancestors of head! */
115 mark_ancestors((ptr_definition)head->value_1,flags);
116 }
117 else
118 tail = appendIntList(tail,
119 ((ptr_definition )head->value_1)->parents);
120 flags[len] = 1;
121 }
122 head = head->next;
123 }
124 return found;
125 }
bit_length
long bit_length(ptr_int_list c)
Definition: types.c:1648
or_codes
void or_codes(ptr_int_list u, ptr_int_list v)
Definition: types.c:780
appendIntList
ptr_int_list appendIntList(ptr_int_list tail, ptr_int_list more)
Definition: lub.c:28
top
ptr_definition top
Definition: def_glob.h:106
NULL
#define NULL
Definition: def_const.h:203
mark_ancestors
void mark_ancestors(ptr_definition def, long *flags)
Definition: lub.c:45
wl_int_list
Definition: def_struct.h:53
built_in
ptr_definition built_in
Definition: def_glob.h:75
STACK_ALLOC
#define STACK_ALLOC(A)
Definition: def_macro.h:16
wl_definition
Definition: def_struct.h:121
sub_CodeType
long sub_CodeType(ptr_int_list c1, ptr_int_list c2)
Definition: types.c:1522
wl_int_list::value_1
GENERIC value_1
Definition: def_struct.h:54
assert
#define assert(N)
Definition: memory.c:104
wl_int_list::next
ptr_int_list next
Definition: def_struct.h:55
wl_definition::parents
ptr_int_list parents
Definition: def_struct.h:130

ptr_int_list lub | ( | ptr_psi_term | a,
|  | ptr_psi_term | b,
|  | ptr_psi_term * | pp
| ) |  |

Definition at line 150 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.

154 {
155 ptr_definition ta; /* type of psi term a */
156 ptr_definition tb; /* type of psi term b */
157 long *flags; /* set to 1 if this type has been checked in
158 * the lub search.
159 */
160 ptr_int_list ans;
161 ptr_int_list pattern;
162 long found;
163
164 ta = a->type;
165 tb = b->type;
166
167 /* special cases first */
168
169 if (isValue(a) && isValue(b) && sub_type(ta,tb) && sub_type(tb,ta))
170 {
171 /* special case of two values being of same type. Check that they
172 * might actually be same value before returning the type
173 */
174 if (isSubTypeValue(a, b))
175 {
176 /* since we alreadyuu know they are both values, isSubTypeValue
177 * returns TRUE if they are same value, else false
178 */
179
180 *pp = a;
181 return NULL;
182 }
183 }
184
185 if (sub_type(ta, tb)) return makeUnitList(tb);
186 if (sub_type(tb, ta)) return makeUnitList(ta);
187
188 /* ta has the lub of tb&ta without the high bit set, search upwards for a
189 * type that has the same lower bits as ta
190 */
191
192 /* get the pattern to search for */
193
194 pattern = copyTypeCode(ta->code);
195 or_codes(pattern, tb->code); /* pattern to search for */
196 ans = copyTypeCode(pattern); /* resulting pattern */
197
198 /* initialize the table to be non-searched */
199
200 flags = (long *)stack_alloc(sizeof(unsigned long) * type_count);
201 memset(flags, 0, sizeof(unsigned long) * type_count);
202
203 /* now do a breadth first search for each of arg1 and arg2 */
204
205 found = bfs(ta, ans, pattern, flags);
206 found += bfs(tb, ans, pattern, flags);
207
208 if (found)
209 ans = decode(ans);
210 else
211 ans = makeUnitList(top);
212
213 return ans;
214 }
isSubTypeValue
int isSubTypeValue(ptr_psi_term arg1, ptr_psi_term arg2)
Definition: bi_type.c:163
type_count
long type_count
Definition: def_glob.h:46
decode
ptr_int_list decode(ptr_int_list c)
Definition: types.c:1678
bfs
static long bfs(ptr_definition p, ptr_int_list ans, ptr_int_list pattern, long *flags)
Definition: lub.c:66
or_codes
void or_codes(ptr_int_list u, ptr_int_list v)
Definition: types.c:780
top
ptr_definition top
Definition: def_glob.h:106
NULL
#define NULL
Definition: def_const.h:203
sub_type
long sub_type(ptr_definition t1, ptr_definition t2)
Definition: types.c:1544
wl_int_list
Definition: def_struct.h:53
wl_definition
Definition: def_struct.h:121
copyTypeCode
ptr_int_list copyTypeCode(ptr_int_list u)
Definition: types.c:760
wl_definition::code
ptr_int_list code
Definition: def_struct.h:129
isValue
long isValue(ptr_psi_term p)
Definition: bi_type.c:541
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
makeUnitList
static ptr_int_list makeUnitList(ptr_definition x)
Definition: lub.c:132
stack_alloc
GENERIC stack_alloc(long s)
Definition: memory.c:1542

static ptr_int_list makeUnitList | ( | ptr_definition | x | ) |
| static

Definition at line 132 of file lub.c.

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

134 {
135 ptr_int_list ans;
136
137 ans = STACK_ALLOC(int_list);
138 ans->value_1 = (GENERIC )x;
139 ans->next = NULL;
140 return ans;
141 }
NULL
#define NULL
Definition: def_const.h:203
wl_int_list
Definition: def_struct.h:53
STACK_ALLOC
#define STACK_ALLOC(A)
Definition: def_macro.h:16
wl_int_list::value_1
GENERIC value_1
Definition: def_struct.h:54
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
wl_int_list::next
ptr_int_list next
Definition: def_struct.h:55

void mark_ancestors | ( | ptr_definition | def,
|  | long * | flags
| ) |  |

Definition at line 45 of file lub.c.

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

48 {
49 ptr_int_list par;
50
51 par=def->parents;
52 while (par) {
53 ptr_definition p;
54 long len;
55
56 p=(ptr_definition)par->value_1;
57 len=bit_length(p->code);
58 if (!flags[len]) {
59 flags[len]=1;
60 mark_ancestors(p, flags);
61 }
62 par=par->next;
63 }
64 }
bit_length
long bit_length(ptr_int_list c)
Definition: types.c:1648
mark_ancestors
void mark_ancestors(ptr_definition def, long *flags)
Definition: lub.c:45
wl_int_list
Definition: def_struct.h:53
ptr_definition
struct wl_definition * ptr_definition
Definition: def_struct.h:31
wl_definition
Definition: def_struct.h:121
wl_definition::code
ptr_int_list code
Definition: def_struct.h:129
wl_int_list::value_1
GENERIC value_1
Definition: def_struct.h:54
wl_int_list::next
ptr_int_list next
Definition: def_struct.h:55
wl_definition::parents
ptr_int_list parents
Definition: def_struct.h:130