annotate lwlib/lw_expr.c @ 336:401587ab6a09

checkpoint
author lost
date Fri, 05 Mar 2010 02:34:16 +0000
parents 9f58e3bca6e3
children 04c80c51b16a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
1 /*
f2173d18c73f Checkpoint
lost
parents:
diff changeset
2 lwexpr.c
f2173d18c73f Checkpoint
lost
parents:
diff changeset
3
f2173d18c73f Checkpoint
lost
parents:
diff changeset
4 Copyright © 2010 William Astle
f2173d18c73f Checkpoint
lost
parents:
diff changeset
5
f2173d18c73f Checkpoint
lost
parents:
diff changeset
6 This file is part of LWTOOLS.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
7
f2173d18c73f Checkpoint
lost
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
f2173d18c73f Checkpoint
lost
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
f2173d18c73f Checkpoint
lost
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
f2173d18c73f Checkpoint
lost
parents:
diff changeset
11 version.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
12
f2173d18c73f Checkpoint
lost
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
f2173d18c73f Checkpoint
lost
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f2173d18c73f Checkpoint
lost
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
f2173d18c73f Checkpoint
lost
parents:
diff changeset
16 more details.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
17
f2173d18c73f Checkpoint
lost
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
f2173d18c73f Checkpoint
lost
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
20 */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
21
f2173d18c73f Checkpoint
lost
parents:
diff changeset
22 #include <config.h>
f2173d18c73f Checkpoint
lost
parents:
diff changeset
23
f2173d18c73f Checkpoint
lost
parents:
diff changeset
24 #include <stdarg.h>
f2173d18c73f Checkpoint
lost
parents:
diff changeset
25 #include <stdio.h>
f2173d18c73f Checkpoint
lost
parents:
diff changeset
26 #include <string.h>
f2173d18c73f Checkpoint
lost
parents:
diff changeset
27
f2173d18c73f Checkpoint
lost
parents:
diff changeset
28 #define ___lw_expr_c_seen___
f2173d18c73f Checkpoint
lost
parents:
diff changeset
29 #include "lw_alloc.h"
f2173d18c73f Checkpoint
lost
parents:
diff changeset
30 #include "lw_expr.h"
f2173d18c73f Checkpoint
lost
parents:
diff changeset
31 #include "lw_error.h"
f2173d18c73f Checkpoint
lost
parents:
diff changeset
32 #include "lw_string.h"
f2173d18c73f Checkpoint
lost
parents:
diff changeset
33
f2173d18c73f Checkpoint
lost
parents:
diff changeset
34 lw_expr_t lw_expr_create(void)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
35 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
36 lw_expr_t r;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
37
f2173d18c73f Checkpoint
lost
parents:
diff changeset
38 r = lw_alloc(sizeof(struct lw_expr_priv));
f2173d18c73f Checkpoint
lost
parents:
diff changeset
39 r -> refcount = 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
40 r -> operands = NULL;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
41
f2173d18c73f Checkpoint
lost
parents:
diff changeset
42 return r;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
43 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
44
f2173d18c73f Checkpoint
lost
parents:
diff changeset
45 /* useful for constant expression construction */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
46 /* lw_expr_deref(lw_expr_create(...)) */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
47 /* use of this function on an expression that is not already referenced by the caller */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
48 lw_expr_t lw_expr_deref(lw_expr_t r)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
49 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
50 r -> refcount--;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
51 return r;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
52 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
53
f2173d18c73f Checkpoint
lost
parents:
diff changeset
54 void lw_expr_destroy(lw_expr_t E)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
55 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
56 E -> refcount--;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
57 if (E -> refcount <= 0)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
58 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
59 struct lw_expr_opers *o;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
60 for (o = E -> operands; o; o = o -> next)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
61 lw_expr_destroy(o -> p);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
62 if (E -> type == lw_expr_type_var)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
63 lw_free(E -> value2);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
64 lw_free(E);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
65 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
66 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
67
f2173d18c73f Checkpoint
lost
parents:
diff changeset
68 lw_expr_t lw_expr_copy(lw_expr_t E)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
69 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
70 E -> refcount++;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
71 return E;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
72 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
73
f2173d18c73f Checkpoint
lost
parents:
diff changeset
74 void lw_expr_add_operand(lw_expr_t E, lw_expr_t O)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
75 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
76 struct lw_expr_opers *o, *t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
77
f2173d18c73f Checkpoint
lost
parents:
diff changeset
78 o = lw_alloc(sizeof(struct lw_expr_opers));
f2173d18c73f Checkpoint
lost
parents:
diff changeset
79 o -> p = lw_expr_copy(O);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
80 o -> next = NULL;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
81 for (t = E -> operands; t && t -> next; t = t -> next)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
82 /* do nothing */ ;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
83
f2173d18c73f Checkpoint
lost
parents:
diff changeset
84 if (t)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
85 t -> next = o;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
86 else
f2173d18c73f Checkpoint
lost
parents:
diff changeset
87 E -> operands = o;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
88 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
89
f2173d18c73f Checkpoint
lost
parents:
diff changeset
90 /* actually duplicates the entire expression */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
91 lw_expr_t lw_expr_deepcopy(lw_expr_t E)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
92 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
93 lw_expr_t r, t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
94 struct lw_expr_opers *o;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
95
f2173d18c73f Checkpoint
lost
parents:
diff changeset
96 r = lw_alloc(sizeof(struct lw_expr_priv));
f2173d18c73f Checkpoint
lost
parents:
diff changeset
97 *r = *E;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
98 r -> refcount = 1;
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
99 r -> operands = NULL;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
100
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
101 if (E -> type == lw_expr_type_var)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
102 r -> value2 = lw_strdup(E -> value2);
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
103 for (o = E -> operands; o; o = o -> next)
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
104 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
105 lw_expr_add_operand(r, lw_expr_deref(lw_expr_deepcopy(o -> p)));
f2173d18c73f Checkpoint
lost
parents:
diff changeset
106 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
107
f2173d18c73f Checkpoint
lost
parents:
diff changeset
108 return r;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
109 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
110
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
111 lw_expr_t lw_expr_build_aux(int exprtype, va_list args)
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
112 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
113 lw_expr_t r;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
114 int t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
115 void *p;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
116
f2173d18c73f Checkpoint
lost
parents:
diff changeset
117 lw_expr_t te1, te2;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
118
f2173d18c73f Checkpoint
lost
parents:
diff changeset
119 r = lw_expr_create();
f2173d18c73f Checkpoint
lost
parents:
diff changeset
120
f2173d18c73f Checkpoint
lost
parents:
diff changeset
121 switch (exprtype)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
122 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
123 case lw_expr_type_int:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
124 t = va_arg(args, int);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
125 r -> type = lw_expr_type_int;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
126 r -> value = t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
127 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
128
f2173d18c73f Checkpoint
lost
parents:
diff changeset
129 case lw_expr_type_var:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
130 p = va_arg(args, char *);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
131 r -> type = lw_expr_type_var;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
132 r -> value2 = lw_strdup(p);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
133 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
134
f2173d18c73f Checkpoint
lost
parents:
diff changeset
135 case lw_expr_type_special:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
136 t = va_arg(args, int);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
137 p = va_arg(args, char *);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
138 r -> type = lw_expr_type_special;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
139 r -> value2 = p;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
140 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
141
f2173d18c73f Checkpoint
lost
parents:
diff changeset
142 case lw_expr_type_oper:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
143 t = va_arg(args, int);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
144 te1 = va_arg(args, lw_expr_t);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
145 if (t != lw_expr_oper_com && t != lw_expr_oper_neg)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
146 te2 = va_arg(args, lw_expr_t);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
147 else
f2173d18c73f Checkpoint
lost
parents:
diff changeset
148 te2 = NULL;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
149
f2173d18c73f Checkpoint
lost
parents:
diff changeset
150 r -> type = lw_expr_type_oper;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
151 r -> value = t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
152 lw_expr_add_operand(r, te1);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
153 lw_expr_add_operand(r, te2);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
154 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
155
f2173d18c73f Checkpoint
lost
parents:
diff changeset
156 default:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
157 lw_error("Invalid expression type specified to lw_expr_build");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
158 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
159
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
160 return r;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
161 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
162
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
163 lw_expr_t lw_expr_build(int exprtype, ...)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
164 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
165 va_list args;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
166 lw_expr_t r;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
167
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
168 va_start(args, exprtype);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
169 r = lw_expr_build_aux(exprtype, args);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
170 va_end(args);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
171 return r;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
172 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
173
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
174 lw_expr_t lw_expr_build_noref(int exprtype, ...)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
175 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
176 va_list args;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
177 lw_expr_t r;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
178
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
179 va_start(args, exprtype);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
180 r = lw_expr_build_aux(exprtype, args);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
181 r -> refcount--;
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
182 va_end(args);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
183 return r;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
184 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
185
f2173d18c73f Checkpoint
lost
parents:
diff changeset
186 void lw_expr_print(lw_expr_t E)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
187 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
188 struct lw_expr_opers *o;
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
189 int c = 0;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
190
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
191 for (o = E -> operands; o; o = o -> next)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
192 {
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
193 c++;
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
194 lw_expr_print(o -> p);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
195 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
196
f2173d18c73f Checkpoint
lost
parents:
diff changeset
197 switch (E -> type)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
198 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
199 case lw_expr_type_int:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
200 printf("%d ", E -> value);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
201 break;
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
202
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
203 case lw_expr_type_var:
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
204 printf("V(%s) ", (char *)(E -> value2));
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
205 break;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
206
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
207 case lw_expr_type_special:
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
208 printf("S(%d,%p) ", E -> value, E -> value2);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
209 break;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
210
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
211 case lw_expr_type_oper:
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
212 printf("[%d]", c);
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
213 switch (E -> value)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
214 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
215 case lw_expr_oper_plus:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
216 printf("+ ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
217 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
218
f2173d18c73f Checkpoint
lost
parents:
diff changeset
219 case lw_expr_oper_minus:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
220 printf("- ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
221 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
222
f2173d18c73f Checkpoint
lost
parents:
diff changeset
223 case lw_expr_oper_times:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
224 printf("* ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
225 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
226
f2173d18c73f Checkpoint
lost
parents:
diff changeset
227 case lw_expr_oper_divide:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
228 printf("/ ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
229 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
230
f2173d18c73f Checkpoint
lost
parents:
diff changeset
231 case lw_expr_oper_mod:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
232 printf("%% ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
233 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
234
f2173d18c73f Checkpoint
lost
parents:
diff changeset
235 case lw_expr_oper_intdiv:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
236 printf("\\ ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
237 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
238
f2173d18c73f Checkpoint
lost
parents:
diff changeset
239 case lw_expr_oper_bwand:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
240 printf("BWAND ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
241 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
242
f2173d18c73f Checkpoint
lost
parents:
diff changeset
243 case lw_expr_oper_bwor:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
244 printf("BWOR ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
245 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
246
f2173d18c73f Checkpoint
lost
parents:
diff changeset
247 case lw_expr_oper_bwxor:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
248 printf("BWXOR ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
249 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
250
f2173d18c73f Checkpoint
lost
parents:
diff changeset
251 case lw_expr_oper_and:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
252 printf("AND ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
253 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
254
f2173d18c73f Checkpoint
lost
parents:
diff changeset
255 case lw_expr_oper_or:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
256 printf("OR ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
257 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
258
f2173d18c73f Checkpoint
lost
parents:
diff changeset
259 case lw_expr_oper_neg:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
260 printf("NEG ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
261 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
262
f2173d18c73f Checkpoint
lost
parents:
diff changeset
263 case lw_expr_oper_com:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
264 printf("COM ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
265 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
266
f2173d18c73f Checkpoint
lost
parents:
diff changeset
267 default:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
268 printf("OPER ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
269 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
270 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
271 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
272 default:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
273 printf("ERR ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
274 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
275 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
276 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
277
f2173d18c73f Checkpoint
lost
parents:
diff changeset
278 /*
f2173d18c73f Checkpoint
lost
parents:
diff changeset
279 Return:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
280 nonzero if expressions are the same (identical pointers or matching values)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
281 zero if expressions are not the same
f2173d18c73f Checkpoint
lost
parents:
diff changeset
282
f2173d18c73f Checkpoint
lost
parents:
diff changeset
283 */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
284 int lw_expr_compare(lw_expr_t E1, lw_expr_t E2)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
285 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
286 struct lw_expr_opers *o1, *o2;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
287
f2173d18c73f Checkpoint
lost
parents:
diff changeset
288 if (E1 == E2)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
289 return 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
290
f2173d18c73f Checkpoint
lost
parents:
diff changeset
291 if (!(E1 -> type == E2 -> type && E1 -> value == E2 -> value))
f2173d18c73f Checkpoint
lost
parents:
diff changeset
292 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
293
f2173d18c73f Checkpoint
lost
parents:
diff changeset
294 if (E1 -> type == lw_expr_type_var)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
295 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
296 if (!strcmp(E1 -> value2, E2 -> value2))
f2173d18c73f Checkpoint
lost
parents:
diff changeset
297 return 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
298 else
f2173d18c73f Checkpoint
lost
parents:
diff changeset
299 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
300 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
301
f2173d18c73f Checkpoint
lost
parents:
diff changeset
302 if (E1 -> type == lw_expr_type_special)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
303 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
304 if (E1 -> value2 == E2 -> value2)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
305 return 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
306 else
f2173d18c73f Checkpoint
lost
parents:
diff changeset
307 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
308 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
309
f2173d18c73f Checkpoint
lost
parents:
diff changeset
310 for (o1 = E1 -> operands, o2 = E2 -> operands; o1 && o2; o1 = o1 -> next, o2 = o2 -> next)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
311 if (lw_expr_compare(o1 -> p, o2 -> p) == 0)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
312 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
313 if (o1 || o2)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
314 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
315
f2173d18c73f Checkpoint
lost
parents:
diff changeset
316 return 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
317 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
318
f2173d18c73f Checkpoint
lost
parents:
diff changeset
319 /* return true if E is an operator of type oper */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
320 int lw_expr_isoper(lw_expr_t E, int oper)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
321 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
322 if (E -> type == lw_expr_type_oper && E -> value == oper)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
323 return 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
324 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
325 }
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
326
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
327
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
328 void lw_expr_simplify_sortconstfirst(lw_expr_t E)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
329 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
330 struct lw_expr_opers *o;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
331
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
332 for (o = E -> operands; o; o = o -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
333 lw_expr_simplify_sortconstfirst(o -> p);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
334
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
335 for (o = E -> operands; o; o = o -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
336 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
337 if (o -> p -> type == lw_expr_type_int && o != E -> operands)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
338 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
339 struct lw_expr_opers *o2;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
340 for (o2 = E -> operands; o2 -> next != o; o2 = o2 -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
341 /* do nothing */ ;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
342 o2 -> next = o -> next;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
343 o -> next = E -> operands;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
344 E -> operands = o;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
345 o = o2;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
346 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
347 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
348 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
349
336
401587ab6a09 checkpoint
lost
parents: 335
diff changeset
350 void lw_expr_sortoperandlist(struct lw_expr_opers **o)
401587ab6a09 checkpoint
lost
parents: 335
diff changeset
351 {
401587ab6a09 checkpoint
lost
parents: 335
diff changeset
352 fprintf(stderr, "lw_expr_sortoperandlist() not yet implemented\n");
401587ab6a09 checkpoint
lost
parents: 335
diff changeset
353 }
401587ab6a09 checkpoint
lost
parents: 335
diff changeset
354
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
355 // return 1 if the operand lists match, 0 if not
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
356 // may re-order the argument lists
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
357 int lw_expr_simplify_compareoperandlist(struct lw_expr_opers **ol1, struct lw_expr_opers **ol2)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
358 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
359 struct lw_expr_opers *o1, *o2;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
360
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
361 lw_expr_sortoperandlist(ol1);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
362 lw_expr_sortoperandlist(ol2);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
363
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
364 for (o1 = *ol1, o2 = *ol2; o1 && o2; o1 = o1 -> next, o2 = o2 -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
365 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
366 if (!lw_expr_compare(o1 -> p, o2 -> p))
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
367 return 0;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
368 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
369 if (o1 || o2)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
370 return 0;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
371 return 1;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
372 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
373
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
374 void lw_expr_simplify(lw_expr_t E)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
375 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
376 struct lw_expr_opers *o;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
377
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
378 // sort "constants" to the start of each operand list for + and *
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
379 lw_expr_simplify_sortconstfirst(E);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
380
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
381 // non-operators have no simplification to do!
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
382 if (E -> type != lw_expr_type_oper)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
383 return;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
384
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
385 if (E -> value == lw_expr_oper_times)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
386 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
387 for (o = E -> operands; o; o = o -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
388 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
389 if (o -> p -> type == lw_expr_type_int && o -> p -> value == 0)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
390 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
391 // one operand of times is 0, replace operation with 0
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
392 while (E -> operands)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
393 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
394 o = E -> operands;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
395 E -> operands = o -> next;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
396 lw_expr_destroy(o -> p);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
397 lw_free(o);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
398 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
399 E -> type = lw_expr_type_int;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
400 E -> value = 0;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
401 return;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
402 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
403 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
404 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
405
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
406 // look for like terms and collect them together
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
407 if (E -> value == lw_expr_oper_plus)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
408 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
409 for (o = E -> operands; o; o = o -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
410 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
411 if (o -> p -> type == lw_expr_type_oper && o -> p -> value == lw_expr_oper_times)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
412 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
413 // we have a "times" here
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
414 // find first non-const operand
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
415 struct lw_expr_opers *op1, *op2, *o2;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
416 for (op1 = o -> p -> operands; op1; op1 = op1 -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
417 if (op1 -> p -> type != lw_expr_type_int)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
418 break;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
419
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
420 for (o2 = o -> next; o2; o2 = o2 -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
421 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
422 if (o2 -> p -> type == lw_expr_type_oper && o2 -> p -> value == lw_expr_oper_times)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
423 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
424 // another "times"
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
425 for (op2 = o2 -> p -> operands; op2; op2 = op2 -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
426 if (op2 -> p -> type != lw_expr_type_int)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
427 break;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
428
336
401587ab6a09 checkpoint
lost
parents: 335
diff changeset
429 if (lw_expr_simplify_compareoperandlist(&op1, &op2))
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
430 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
431 // we have like terms here
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
432 // do something about it
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
433 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
434 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
435 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
436 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
437 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
438 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
439
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
440
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
441 for (o = E -> operands; o; o = o -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
442 lw_expr_simplify(o -> p);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
443
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
444 if (E -> value == lw_expr_oper_plus)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
445 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
446 int c = 0, t = 0;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
447 for (o = E -> operands; o; o = o -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
448 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
449 t++;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
450 if (!(o -> p -> type == lw_expr_type_int && o -> p -> value == 0))
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
451 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
452 c++;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
453 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
454 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
455 if (c == 1)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
456 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
457 lw_expr_t r;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
458 // find the value and "move it up"
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
459 while (E -> operands)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
460 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
461 o = E -> operands;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
462 if (o -> p -> type != lw_expr_type_int || o -> p -> value != 0)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
463 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
464 r = lw_expr_deepcopy(o -> p);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
465 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
466 E -> operands = o -> next;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
467 lw_expr_destroy(o -> p);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
468 lw_free(o);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
469 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
470 *E = *r;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
471 return;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
472 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
473 else if (c == 0)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
474 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
475 // replace with 0
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
476 while (E -> operands)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
477 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
478 o = E -> operands;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
479 E -> operands = o -> next;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
480 lw_expr_destroy(o -> p);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
481 lw_free(o);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
482 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
483 E -> type = lw_expr_type_int;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
484 E -> value = 0;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
485 return;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
486 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
487 else if (c != t)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
488 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
489 // collapse out zero terms
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
490 struct lw_expr_opers *o2;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
491
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
492 for (o = E -> operands; o; o = o -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
493 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
494 if (o -> p -> type == lw_expr_type_int && o -> p -> value == 0)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
495 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
496 if (o == E -> operands)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
497 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
498 E -> operands = o -> next;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
499 lw_expr_destroy(o -> p);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
500 lw_free(o);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
501 o = E -> operands;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
502 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
503 else
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
504 {
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
505 for (o2 = E -> operands; o2 -> next == o; o2 = o2 -> next)
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
506 /* do nothing */ ;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
507 o2 -> next = o -> next;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
508 lw_expr_destroy(o -> p);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
509 lw_free(o);
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
510 o = o2;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
511 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
512 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
513 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
514 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
515 return;
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
516 }
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
517 }