annotate lwlib/lw_expr.c @ 334:f2173d18c73f

Checkpoint
author lost
date Thu, 04 Mar 2010 02:24:38 +0000
parents
children 9f58e3bca6e3
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;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
99
f2173d18c73f Checkpoint
lost
parents:
diff changeset
100 if (E -> type == lw_expr_type_var)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
101 r -> value2 = lw_strdup(E -> value2);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
102
f2173d18c73f Checkpoint
lost
parents:
diff changeset
103 for (o = r -> operands; o; o = o -> next)
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
f2173d18c73f Checkpoint
lost
parents:
diff changeset
111 lw_expr_t lw_expr_build(int exprtype, ...)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
112 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
113 va_list args;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
114 lw_expr_t r;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
115 int t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
116 void *p;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
117
f2173d18c73f Checkpoint
lost
parents:
diff changeset
118 lw_expr_t te1, te2;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
119
f2173d18c73f Checkpoint
lost
parents:
diff changeset
120 r = lw_expr_create();
f2173d18c73f Checkpoint
lost
parents:
diff changeset
121 va_start(args, exprtype);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
122
f2173d18c73f Checkpoint
lost
parents:
diff changeset
123 switch (exprtype)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
124 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
125 case lw_expr_type_int:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
126 t = va_arg(args, int);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
127 r -> type = lw_expr_type_int;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
128 r -> value = t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
129 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
130
f2173d18c73f Checkpoint
lost
parents:
diff changeset
131 case lw_expr_type_var:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
132 p = va_arg(args, char *);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
133 r -> type = lw_expr_type_var;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
134 r -> value2 = lw_strdup(p);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
135 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
136
f2173d18c73f Checkpoint
lost
parents:
diff changeset
137 case lw_expr_type_special:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
138 t = va_arg(args, int);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
139 p = va_arg(args, char *);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
140 r -> type = lw_expr_type_special;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
141 r -> value2 = p;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
142 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
143
f2173d18c73f Checkpoint
lost
parents:
diff changeset
144 case lw_expr_type_oper:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
145 t = va_arg(args, int);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
146 te1 = va_arg(args, lw_expr_t);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
147 if (t != lw_expr_oper_com && t != lw_expr_oper_neg)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
148 te2 = va_arg(args, lw_expr_t);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
149 else
f2173d18c73f Checkpoint
lost
parents:
diff changeset
150 te2 = NULL;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
151
f2173d18c73f Checkpoint
lost
parents:
diff changeset
152 r -> type = lw_expr_type_oper;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
153 r -> value = t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
154 lw_expr_add_operand(r, te1);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
155 lw_expr_add_operand(r, te2);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
156 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
157
f2173d18c73f Checkpoint
lost
parents:
diff changeset
158 default:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
159 lw_error("Invalid expression type specified to lw_expr_build");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
160 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
161
f2173d18c73f Checkpoint
lost
parents:
diff changeset
162 va_end(args);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
163 return r;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
164 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
165
f2173d18c73f Checkpoint
lost
parents:
diff changeset
166 void lw_expr_print(lw_expr_t E)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
167 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
168 struct lw_expr_opers *o;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
169
f2173d18c73f Checkpoint
lost
parents:
diff changeset
170 for (o = E -> operands; o; o = o -> next)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
171 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
172 lw_expr_print(o -> p);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
173 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
174
f2173d18c73f Checkpoint
lost
parents:
diff changeset
175 switch (E -> type)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
176 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
177 case lw_expr_type_int:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
178 printf("%d ", E -> value);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
179 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
180 case lw_expr_type_oper:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
181 switch (E -> value)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
182 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
183 case lw_expr_oper_plus:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
184 printf("+ ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
185 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
186
f2173d18c73f Checkpoint
lost
parents:
diff changeset
187 case lw_expr_oper_minus:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
188 printf("- ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
189 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
190
f2173d18c73f Checkpoint
lost
parents:
diff changeset
191 case lw_expr_oper_times:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
192 printf("* ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
193 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
194
f2173d18c73f Checkpoint
lost
parents:
diff changeset
195 case lw_expr_oper_divide:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
196 printf("/ ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
197 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
198
f2173d18c73f Checkpoint
lost
parents:
diff changeset
199 case lw_expr_oper_mod:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
200 printf("%% ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
201 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
202
f2173d18c73f Checkpoint
lost
parents:
diff changeset
203 case lw_expr_oper_intdiv:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
204 printf("\\ ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
205 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
206
f2173d18c73f Checkpoint
lost
parents:
diff changeset
207 case lw_expr_oper_bwand:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
208 printf("BWAND ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
209 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
210
f2173d18c73f Checkpoint
lost
parents:
diff changeset
211 case lw_expr_oper_bwor:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
212 printf("BWOR ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
213 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
214
f2173d18c73f Checkpoint
lost
parents:
diff changeset
215 case lw_expr_oper_bwxor:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
216 printf("BWXOR ");
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_and:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
220 printf("AND ");
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_or:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
224 printf("OR ");
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_neg:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
228 printf("NEG ");
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_com:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
232 printf("COM ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
233 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
234
f2173d18c73f Checkpoint
lost
parents:
diff changeset
235 default:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
236 printf("OPER ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
237 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
238 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
239 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
240 default:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
241 printf("ERR ");
f2173d18c73f Checkpoint
lost
parents:
diff changeset
242 break;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
243 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
244 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
245
f2173d18c73f Checkpoint
lost
parents:
diff changeset
246 /*
f2173d18c73f Checkpoint
lost
parents:
diff changeset
247 Return:
f2173d18c73f Checkpoint
lost
parents:
diff changeset
248 nonzero if expressions are the same (identical pointers or matching values)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
249 zero if expressions are not the same
f2173d18c73f Checkpoint
lost
parents:
diff changeset
250
f2173d18c73f Checkpoint
lost
parents:
diff changeset
251 */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
252 int lw_expr_compare(lw_expr_t E1, lw_expr_t E2)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
253 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
254 struct lw_expr_opers *o1, *o2;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
255
f2173d18c73f Checkpoint
lost
parents:
diff changeset
256 if (E1 == E2)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
257 return 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
258
f2173d18c73f Checkpoint
lost
parents:
diff changeset
259 if (!(E1 -> type == E2 -> type && E1 -> value == E2 -> value))
f2173d18c73f Checkpoint
lost
parents:
diff changeset
260 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
261
f2173d18c73f Checkpoint
lost
parents:
diff changeset
262 if (E1 -> type == lw_expr_type_var)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
263 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
264 if (!strcmp(E1 -> value2, E2 -> value2))
f2173d18c73f Checkpoint
lost
parents:
diff changeset
265 return 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
266 else
f2173d18c73f Checkpoint
lost
parents:
diff changeset
267 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
268 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
269
f2173d18c73f Checkpoint
lost
parents:
diff changeset
270 if (E1 -> type == lw_expr_type_special)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
271 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
272 if (E1 -> value2 == E2 -> value2)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
273 return 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
274 else
f2173d18c73f Checkpoint
lost
parents:
diff changeset
275 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
276 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
277
f2173d18c73f Checkpoint
lost
parents:
diff changeset
278 for (o1 = E1 -> operands, o2 = E2 -> operands; o1 && o2; o1 = o1 -> next, o2 = o2 -> next)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
279 if (lw_expr_compare(o1 -> p, o2 -> p) == 0)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
280 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
281 if (o1 || o2)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
282 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
283
f2173d18c73f Checkpoint
lost
parents:
diff changeset
284 return 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
285 }
f2173d18c73f Checkpoint
lost
parents:
diff changeset
286
f2173d18c73f Checkpoint
lost
parents:
diff changeset
287 /* return true if E is an operator of type oper */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
288 int lw_expr_isoper(lw_expr_t E, int oper)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
289 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
290 if (E -> type == lw_expr_type_oper && E -> value == oper)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
291 return 1;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
292 return 0;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
293 }