Wild Life: lub.c Source File

Wild Life 2.30

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros
lub.c
Go to the documentation of this file.
1
9 /*
10 * Copyright (c) 1992 Digital Equipment Corporation
11 * All Rights Reserved.
12 *
13 * The standard digital prl copyrights exist and where compatible
14 * the below also exists.
15 * Permission to use, copy, modify, and distribute this
16 * software and its documentation for any purpose and without
17 * fee is hereby granted, provided that the above copyright
18 * notice appear in all copies. Copyright holder(s) make no
19 * representation about the suitability of this software for
20 * any purpose. It is provided "as is" without express or
21 * implied warranty.
22 *
23 * Author: Seth Copen Goldstein
24 * Version: 26
25 * Creation Date: Fri Jun 5 12:14:39 1992
26 * Filename: lub.c
27 * History:
28 */
29
30 #include "defs.h"
31
40 ptr_int_list appendIntList(ptr_int_list tail, ptr_int_list more)
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 }
60 void mark_ancestors(ptr_definition def, long *flags)
61 {
62 ptr_int_list par;
63
64 par=def->parents;
65 while (par) {
66 ptr_definition p;
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 }
78
88 static long bfs(ptr_definition p, ptr_int_list ans, ptr_int_list pattern, long *flags)
89 {
90 ptr_int_list head = STACK_ALLOC(int_list);
91 ptr_int_list tail;
92 ptr_int_list par;
93 long len;
94 long found = 0;
95
96 if (p == top)
97 {
98 or_codes((ptr_int_list)ans, (ptr_int_list)top);
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 }
144
152 static ptr_int_list makeUnitList(ptr_definition x)
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 }
161
173 ptr_int_list lub(ptr_psi_term a,ptr_psi_term b,ptr_psi_term *pp)
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 }
235
236
isSubTypeValue
int isSubTypeValue(ptr_psi_term arg1, ptr_psi_term arg2)
isSubTypeValue
Definition: bi_type.c:180
type_count
long type_count
Definition: def_glob.h:1021
bit_length
long bit_length(ptr_int_list c)
bit_length
Definition: types.c:1753
decode
ptr_int_list decode(ptr_int_list c)
decode
Definition: types.c:1784
bfs
static long bfs(ptr_definition p, ptr_int_list ans, ptr_int_list pattern, long *flags)
bfs
Definition: lub.c:88
defs.h
includes
wl_psi_term
Definition: def_struct.h:177
or_codes
void or_codes(ptr_int_list u, ptr_int_list v)
or_codes
Definition: types.c:831
lub
ptr_int_list lub(ptr_psi_term a, ptr_psi_term b, ptr_psi_term *pp)
Definition: lub.c:173
appendIntList
ptr_int_list appendIntList(ptr_int_list tail, ptr_int_list more)
appendIntList
Definition: lub.c:40
NULL
#define NULL
Definition: def_const.h:533
mark_ancestors
void mark_ancestors(ptr_definition def, long *flags)
mark_ancestors
Definition: lub.c:60
built_in
ptr_definition built_in
symbol in bi module
Definition: def_glob.h:199
sub_type
long sub_type(ptr_definition t1, ptr_definition t2)
sub_type
Definition: types.c:1642
wl_int_list
Definition: def_struct.h:84
GENERIC
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_definition
struct wl_definition * ptr_definition
Definition: def_struct.h:59
STACK_ALLOC
#define STACK_ALLOC(A)
Definition: def_macro.h:21
wl_definition
Definition: def_struct.h:145
top
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
copyTypeCode
ptr_int_list copyTypeCode(ptr_int_list u)
copyTypeCode
Definition: types.c:808
sub_CodeType
long sub_CodeType(ptr_int_list c1, ptr_int_list c2)
sub_CodeType
Definition: types.c:1618
wl_definition::code
ptr_int_list code
Definition: def_struct.h:150
isValue
long isValue(ptr_psi_term p)
isValue(p)
Definition: bi_type.c:694
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:181
wl_int_list::value_1
GENERIC value_1
Definition: def_struct.h:85
makeUnitList
static ptr_int_list makeUnitList(ptr_definition x)
makeUnitList
Definition: lub.c:152
stack_alloc
GENERIC stack_alloc(long s)
stack_alloc
Definition: memory.c:1642
assert
#define assert(N)
Definition: memory.c:114
wl_int_list::next
ptr_int_list next
Definition: def_struct.h:86
wl_definition::parents
ptr_int_list parents
Definition: def_struct.h:151