Show More
@@ -149,10 +149,12 def _analyze(x): | |||||
149 | if op == 'not': |
|
149 | if op == 'not': | |
150 | t = _analyze(x[1]) |
|
150 | t = _analyze(x[1]) | |
151 | return (op, t) |
|
151 | return (op, t) | |
152 |
if op |
|
152 | if op == 'and': | |
153 | ta = _analyze(x[1]) |
|
153 | ta = _analyze(x[1]) | |
154 | tb = _analyze(x[2]) |
|
154 | tb = _analyze(x[2]) | |
155 | return (op, ta, tb) |
|
155 | return (op, ta, tb) | |
|
156 | if op == 'minus': | |||
|
157 | return _analyze(('and', x[1], ('not', x[2]))) | |||
156 | if op in {'list', 'or'}: |
|
158 | if op in {'list', 'or'}: | |
157 | ts = tuple(_analyze(y) for y in x[1:]) |
|
159 | ts = tuple(_analyze(y) for y in x[1:]) | |
158 | return (op,) + ts |
|
160 | return (op,) + ts | |
@@ -171,6 +173,11 def analyze(x): | |||||
171 | """ |
|
173 | """ | |
172 | return _analyze(x) |
|
174 | return _analyze(x) | |
173 |
|
175 | |||
|
176 | def _optimizeandops(op, ta, tb): | |||
|
177 | if tb is not None and tb[0] == 'not': | |||
|
178 | return ('minus', ta, tb[1]) | |||
|
179 | return (op, ta, tb) | |||
|
180 | ||||
174 | def _optimize(x): |
|
181 | def _optimize(x): | |
175 | if x is None: |
|
182 | if x is None: | |
176 | return 0, x |
|
183 | return 0, x | |
@@ -188,13 +195,9 def _optimize(x): | |||||
188 | wa, ta = _optimize(x[1]) |
|
195 | wa, ta = _optimize(x[1]) | |
189 | wb, tb = _optimize(x[2]) |
|
196 | wb, tb = _optimize(x[2]) | |
190 | if wa <= wb: |
|
197 | if wa <= wb: | |
191 | return wa, (op, ta, tb) |
|
198 | return wa, _optimizeandops(op, ta, tb) | |
192 | else: |
|
199 | else: | |
193 | return wb, (op, tb, ta) |
|
200 | return wb, _optimizeandops(op, tb, ta) | |
194 | if op == 'minus': |
|
|||
195 | wa, ta = _optimize(x[1]) |
|
|||
196 | wb, tb = _optimize(x[2]) |
|
|||
197 | return max(wa, wb), (op, ta, tb) |
|
|||
198 | if op == 'or': |
|
201 | if op == 'or': | |
199 | ws, ts = zip(*(_optimize(y) for y in x[1:])) |
|
202 | ws, ts = zip(*(_optimize(y) for y in x[1:])) | |
200 | return max(ws), (op,) + ts |
|
203 | return max(ws), (op,) + ts |
@@ -203,6 +203,73 Show parsed tree at stages: | |||||
203 | b1 |
|
203 | b1 | |
204 | b2 |
|
204 | b2 | |
205 |
|
205 | |||
|
206 | Use differencematcher for 'x and not y': | |||
|
207 | ||||
|
208 | $ fileset -p optimized -s 'a* and not a1' | |||
|
209 | * optimized: | |||
|
210 | (minus | |||
|
211 | (symbol 'a*') | |||
|
212 | (symbol 'a1')) | |||
|
213 | * matcher: | |||
|
214 | <differencematcher | |||
|
215 | m1=<patternmatcher patterns='(?:a[^/]*$)'>, | |||
|
216 | m2=<patternmatcher patterns='(?:a1$)'>> | |||
|
217 | a2 | |||
|
218 | ||||
|
219 | $ fileset -p optimized -s '!binary() and a*' | |||
|
220 | * optimized: | |||
|
221 | (minus | |||
|
222 | (symbol 'a*') | |||
|
223 | (func | |||
|
224 | (symbol 'binary') | |||
|
225 | None)) | |||
|
226 | * matcher: | |||
|
227 | <differencematcher | |||
|
228 | m1=<patternmatcher patterns='(?:a[^/]*$)'>, | |||
|
229 | m2=<predicatenmatcher pred=binary>> | |||
|
230 | a1 | |||
|
231 | a2 | |||
|
232 | ||||
|
233 | 'x - y' is rewritten to 'x and not y' first so the operands can be reordered: | |||
|
234 | ||||
|
235 | $ fileset -p analyzed -p optimized -s 'a* - a1' | |||
|
236 | * analyzed: | |||
|
237 | (and | |||
|
238 | (symbol 'a*') | |||
|
239 | (not | |||
|
240 | (symbol 'a1'))) | |||
|
241 | * optimized: | |||
|
242 | (minus | |||
|
243 | (symbol 'a*') | |||
|
244 | (symbol 'a1')) | |||
|
245 | * matcher: | |||
|
246 | <differencematcher | |||
|
247 | m1=<patternmatcher patterns='(?:a[^/]*$)'>, | |||
|
248 | m2=<patternmatcher patterns='(?:a1$)'>> | |||
|
249 | a2 | |||
|
250 | ||||
|
251 | $ fileset -p analyzed -p optimized -s 'binary() - a*' | |||
|
252 | * analyzed: | |||
|
253 | (and | |||
|
254 | (func | |||
|
255 | (symbol 'binary') | |||
|
256 | None) | |||
|
257 | (not | |||
|
258 | (symbol 'a*'))) | |||
|
259 | * optimized: | |||
|
260 | (and | |||
|
261 | (not | |||
|
262 | (symbol 'a*')) | |||
|
263 | (func | |||
|
264 | (symbol 'binary') | |||
|
265 | None)) | |||
|
266 | * matcher: | |||
|
267 | <intersectionmatcher | |||
|
268 | m1=<predicatenmatcher | |||
|
269 | pred=<not | |||
|
270 | <patternmatcher patterns='(?:a[^/]*$)'>>>, | |||
|
271 | m2=<predicatenmatcher pred=binary>> | |||
|
272 | ||||
206 | Test files status |
|
273 | Test files status | |
207 |
|
274 | |||
208 | $ rm a1 |
|
275 | $ rm a1 |
General Comments 0
You need to be logged in to leave comments.
Login now