1 | from asdl import pybase
|
2 | from mycpp import mops
|
3 | from typing import Optional, List, Tuple, Dict, Any, cast, TYPE_CHECKING
|
4 |
|
5 | from asdl import runtime # For runtime.NO_SPID
|
6 | from asdl.runtime import NewRecord, NewLeaf, TraversalState
|
7 | from _devbuild.gen.hnode_asdl import color_e, hnode, hnode_e, hnode_t, Field
|
8 |
|
9 | class expr_e(object):
|
10 | Concatenation = 1
|
11 | Disjunction = 2
|
12 | Conjunction = 3
|
13 | Negation = 4
|
14 | True_ = 5
|
15 | False_ = 6
|
16 | PathTest = 7
|
17 | StatTest = 8
|
18 | DeleteAction = 9
|
19 | PruneAction = 10
|
20 | QuitAction = 11
|
21 | PrintAction = 12
|
22 | LsAction = 13
|
23 | ExecAction = 14
|
24 |
|
25 | _expr_str = {
|
26 | 1: 'Concatenation',
|
27 | 2: 'Disjunction',
|
28 | 3: 'Conjunction',
|
29 | 4: 'Negation',
|
30 | 5: 'True_',
|
31 | 6: 'False_',
|
32 | 7: 'PathTest',
|
33 | 8: 'StatTest',
|
34 | 9: 'DeleteAction',
|
35 | 10: 'PruneAction',
|
36 | 11: 'QuitAction',
|
37 | 12: 'PrintAction',
|
38 | 13: 'LsAction',
|
39 | 14: 'ExecAction',
|
40 | }
|
41 |
|
42 | def expr_str(tag, dot=True):
|
43 | # type: (int, bool) -> str
|
44 | v = _expr_str[tag]
|
45 | if dot:
|
46 | return "expr.%s" % v
|
47 | else:
|
48 | return v
|
49 |
|
50 | class expr_t(pybase.CompoundObj):
|
51 | def tag(self):
|
52 | # type: () -> int
|
53 | return self._type_tag
|
54 |
|
55 | class expr__True_(expr_t):
|
56 | _type_tag = 5
|
57 | __slots__ = ()
|
58 |
|
59 | def __init__(self, ):
|
60 | # type: () -> None
|
61 | pass
|
62 |
|
63 | def PrettyTree(self, do_abbrev, trav=None):
|
64 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
65 | trav = trav or TraversalState()
|
66 | heap_id = id(self)
|
67 | if heap_id in trav.seen:
|
68 | return hnode.AlreadySeen(heap_id)
|
69 | trav.seen[heap_id] = True
|
70 |
|
71 | out_node = NewRecord('expr.True_')
|
72 | L = out_node.fields
|
73 |
|
74 | return out_node
|
75 |
|
76 | class expr__False_(expr_t):
|
77 | _type_tag = 6
|
78 | __slots__ = ()
|
79 |
|
80 | def __init__(self, ):
|
81 | # type: () -> None
|
82 | pass
|
83 |
|
84 | def PrettyTree(self, do_abbrev, trav=None):
|
85 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
86 | trav = trav or TraversalState()
|
87 | heap_id = id(self)
|
88 | if heap_id in trav.seen:
|
89 | return hnode.AlreadySeen(heap_id)
|
90 | trav.seen[heap_id] = True
|
91 |
|
92 | out_node = NewRecord('expr.False_')
|
93 | L = out_node.fields
|
94 |
|
95 | return out_node
|
96 |
|
97 | class expr__DeleteAction(expr_t):
|
98 | _type_tag = 9
|
99 | __slots__ = ()
|
100 |
|
101 | def __init__(self, ):
|
102 | # type: () -> None
|
103 | pass
|
104 |
|
105 | def PrettyTree(self, do_abbrev, trav=None):
|
106 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
107 | trav = trav or TraversalState()
|
108 | heap_id = id(self)
|
109 | if heap_id in trav.seen:
|
110 | return hnode.AlreadySeen(heap_id)
|
111 | trav.seen[heap_id] = True
|
112 |
|
113 | out_node = NewRecord('expr.DeleteAction')
|
114 | L = out_node.fields
|
115 |
|
116 | return out_node
|
117 |
|
118 | class expr__PruneAction(expr_t):
|
119 | _type_tag = 10
|
120 | __slots__ = ()
|
121 |
|
122 | def __init__(self, ):
|
123 | # type: () -> None
|
124 | pass
|
125 |
|
126 | def PrettyTree(self, do_abbrev, trav=None):
|
127 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
128 | trav = trav or TraversalState()
|
129 | heap_id = id(self)
|
130 | if heap_id in trav.seen:
|
131 | return hnode.AlreadySeen(heap_id)
|
132 | trav.seen[heap_id] = True
|
133 |
|
134 | out_node = NewRecord('expr.PruneAction')
|
135 | L = out_node.fields
|
136 |
|
137 | return out_node
|
138 |
|
139 | class expr__QuitAction(expr_t):
|
140 | _type_tag = 11
|
141 | __slots__ = ()
|
142 |
|
143 | def __init__(self, ):
|
144 | # type: () -> None
|
145 | pass
|
146 |
|
147 | def PrettyTree(self, do_abbrev, trav=None):
|
148 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
149 | trav = trav or TraversalState()
|
150 | heap_id = id(self)
|
151 | if heap_id in trav.seen:
|
152 | return hnode.AlreadySeen(heap_id)
|
153 | trav.seen[heap_id] = True
|
154 |
|
155 | out_node = NewRecord('expr.QuitAction')
|
156 | L = out_node.fields
|
157 |
|
158 | return out_node
|
159 |
|
160 | class expr(object):
|
161 | class Concatenation(expr_t):
|
162 | _type_tag = 1
|
163 | __slots__ = ('exprs',)
|
164 |
|
165 | def __init__(self, exprs):
|
166 | # type: (List[expr_t]) -> None
|
167 | self.exprs = exprs
|
168 |
|
169 | @staticmethod
|
170 | def CreateNull(alloc_lists=False):
|
171 | # type: () -> expr.Concatenation
|
172 | return expr.Concatenation([] if alloc_lists else cast('List[expr_t]', None))
|
173 |
|
174 | def PrettyTree(self, do_abbrev, trav=None):
|
175 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
176 | trav = trav or TraversalState()
|
177 | heap_id = id(self)
|
178 | if heap_id in trav.seen:
|
179 | return hnode.AlreadySeen(heap_id)
|
180 | trav.seen[heap_id] = True
|
181 |
|
182 | out_node = NewRecord('expr.Concatenation')
|
183 | L = out_node.fields
|
184 |
|
185 | if self.exprs is not None: # List
|
186 | x0 = hnode.Array([])
|
187 | for i0 in self.exprs:
|
188 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
189 | i0.PrettyTree(do_abbrev, trav=trav))
|
190 | x0.children.append(h)
|
191 | L.append(Field('exprs', x0))
|
192 |
|
193 | return out_node
|
194 |
|
195 | class Disjunction(expr_t):
|
196 | _type_tag = 2
|
197 | __slots__ = ('exprs',)
|
198 |
|
199 | def __init__(self, exprs):
|
200 | # type: (List[expr_t]) -> None
|
201 | self.exprs = exprs
|
202 |
|
203 | @staticmethod
|
204 | def CreateNull(alloc_lists=False):
|
205 | # type: () -> expr.Disjunction
|
206 | return expr.Disjunction([] if alloc_lists else cast('List[expr_t]', None))
|
207 |
|
208 | def PrettyTree(self, do_abbrev, trav=None):
|
209 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
210 | trav = trav or TraversalState()
|
211 | heap_id = id(self)
|
212 | if heap_id in trav.seen:
|
213 | return hnode.AlreadySeen(heap_id)
|
214 | trav.seen[heap_id] = True
|
215 |
|
216 | out_node = NewRecord('expr.Disjunction')
|
217 | L = out_node.fields
|
218 |
|
219 | if self.exprs is not None: # List
|
220 | x0 = hnode.Array([])
|
221 | for i0 in self.exprs:
|
222 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
223 | i0.PrettyTree(do_abbrev, trav=trav))
|
224 | x0.children.append(h)
|
225 | L.append(Field('exprs', x0))
|
226 |
|
227 | return out_node
|
228 |
|
229 | class Conjunction(expr_t):
|
230 | _type_tag = 3
|
231 | __slots__ = ('exprs',)
|
232 |
|
233 | def __init__(self, exprs):
|
234 | # type: (List[expr_t]) -> None
|
235 | self.exprs = exprs
|
236 |
|
237 | @staticmethod
|
238 | def CreateNull(alloc_lists=False):
|
239 | # type: () -> expr.Conjunction
|
240 | return expr.Conjunction([] if alloc_lists else cast('List[expr_t]', None))
|
241 |
|
242 | def PrettyTree(self, do_abbrev, trav=None):
|
243 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
244 | trav = trav or TraversalState()
|
245 | heap_id = id(self)
|
246 | if heap_id in trav.seen:
|
247 | return hnode.AlreadySeen(heap_id)
|
248 | trav.seen[heap_id] = True
|
249 |
|
250 | out_node = NewRecord('expr.Conjunction')
|
251 | L = out_node.fields
|
252 |
|
253 | if self.exprs is not None: # List
|
254 | x0 = hnode.Array([])
|
255 | for i0 in self.exprs:
|
256 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
257 | i0.PrettyTree(do_abbrev, trav=trav))
|
258 | x0.children.append(h)
|
259 | L.append(Field('exprs', x0))
|
260 |
|
261 | return out_node
|
262 |
|
263 | class Negation(expr_t):
|
264 | _type_tag = 4
|
265 | __slots__ = ('expr',)
|
266 |
|
267 | def __init__(self, expr):
|
268 | # type: (expr_t) -> None
|
269 | self.expr = expr
|
270 |
|
271 | @staticmethod
|
272 | def CreateNull(alloc_lists=False):
|
273 | # type: () -> expr.Negation
|
274 | return expr.Negation(cast('expr_t', None))
|
275 |
|
276 | def PrettyTree(self, do_abbrev, trav=None):
|
277 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
278 | trav = trav or TraversalState()
|
279 | heap_id = id(self)
|
280 | if heap_id in trav.seen:
|
281 | return hnode.AlreadySeen(heap_id)
|
282 | trav.seen[heap_id] = True
|
283 |
|
284 | out_node = NewRecord('expr.Negation')
|
285 | L = out_node.fields
|
286 |
|
287 | assert self.expr is not None
|
288 | x0 = self.expr.PrettyTree(do_abbrev, trav=trav)
|
289 | L.append(Field('expr', x0))
|
290 |
|
291 | return out_node
|
292 |
|
293 | True_ = expr__True_()
|
294 |
|
295 | False_ = expr__False_()
|
296 |
|
297 | class PathTest(expr_t):
|
298 | _type_tag = 7
|
299 | __slots__ = ('a', 'p')
|
300 |
|
301 | def __init__(self, a, p):
|
302 | # type: (pathAccessor_t, predicate_t) -> None
|
303 | self.a = a
|
304 | self.p = p
|
305 |
|
306 | @staticmethod
|
307 | def CreateNull(alloc_lists=False):
|
308 | # type: () -> expr.PathTest
|
309 | return expr.PathTest(pathAccessor_e.FullPath, cast('predicate_t', None))
|
310 |
|
311 | def PrettyTree(self, do_abbrev, trav=None):
|
312 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
313 | trav = trav or TraversalState()
|
314 | heap_id = id(self)
|
315 | if heap_id in trav.seen:
|
316 | return hnode.AlreadySeen(heap_id)
|
317 | trav.seen[heap_id] = True
|
318 |
|
319 | out_node = NewRecord('expr.PathTest')
|
320 | L = out_node.fields
|
321 |
|
322 | x0 = hnode.Leaf(pathAccessor_str(self.a), color_e.TypeName)
|
323 | L.append(Field('a', x0))
|
324 |
|
325 | assert self.p is not None
|
326 | x1 = self.p.PrettyTree(do_abbrev, trav=trav)
|
327 | L.append(Field('p', x1))
|
328 |
|
329 | return out_node
|
330 |
|
331 | class StatTest(expr_t):
|
332 | _type_tag = 8
|
333 | __slots__ = ('a', 'p')
|
334 |
|
335 | def __init__(self, a, p):
|
336 | # type: (statAccessor_t, predicate_t) -> None
|
337 | self.a = a
|
338 | self.p = p
|
339 |
|
340 | @staticmethod
|
341 | def CreateNull(alloc_lists=False):
|
342 | # type: () -> expr.StatTest
|
343 | return expr.StatTest(statAccessor_e.AccessTime, cast('predicate_t', None))
|
344 |
|
345 | def PrettyTree(self, do_abbrev, trav=None):
|
346 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
347 | trav = trav or TraversalState()
|
348 | heap_id = id(self)
|
349 | if heap_id in trav.seen:
|
350 | return hnode.AlreadySeen(heap_id)
|
351 | trav.seen[heap_id] = True
|
352 |
|
353 | out_node = NewRecord('expr.StatTest')
|
354 | L = out_node.fields
|
355 |
|
356 | x0 = hnode.Leaf(statAccessor_str(self.a), color_e.TypeName)
|
357 | L.append(Field('a', x0))
|
358 |
|
359 | assert self.p is not None
|
360 | x1 = self.p.PrettyTree(do_abbrev, trav=trav)
|
361 | L.append(Field('p', x1))
|
362 |
|
363 | return out_node
|
364 |
|
365 | DeleteAction = expr__DeleteAction()
|
366 |
|
367 | PruneAction = expr__PruneAction()
|
368 |
|
369 | QuitAction = expr__QuitAction()
|
370 |
|
371 | class PrintAction(expr_t):
|
372 | _type_tag = 12
|
373 | __slots__ = ('file', 'format')
|
374 |
|
375 | def __init__(self, file, format):
|
376 | # type: (Optional[str], Optional[str]) -> None
|
377 | self.file = file
|
378 | self.format = format
|
379 |
|
380 | @staticmethod
|
381 | def CreateNull(alloc_lists=False):
|
382 | # type: () -> expr.PrintAction
|
383 | return expr.PrintAction(cast('Optional[str]', None), cast('Optional[str]', None))
|
384 |
|
385 | def PrettyTree(self, do_abbrev, trav=None):
|
386 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
387 | trav = trav or TraversalState()
|
388 | heap_id = id(self)
|
389 | if heap_id in trav.seen:
|
390 | return hnode.AlreadySeen(heap_id)
|
391 | trav.seen[heap_id] = True
|
392 |
|
393 | out_node = NewRecord('expr.PrintAction')
|
394 | L = out_node.fields
|
395 |
|
396 | if self.file is not None: # Optional
|
397 | x0 = NewLeaf(self.file, color_e.StringConst)
|
398 | L.append(Field('file', x0))
|
399 |
|
400 | if self.format is not None: # Optional
|
401 | x1 = NewLeaf(self.format, color_e.StringConst)
|
402 | L.append(Field('format', x1))
|
403 |
|
404 | return out_node
|
405 |
|
406 | class LsAction(expr_t):
|
407 | _type_tag = 13
|
408 | __slots__ = ('file',)
|
409 |
|
410 | def __init__(self, file):
|
411 | # type: (Optional[str]) -> None
|
412 | self.file = file
|
413 |
|
414 | @staticmethod
|
415 | def CreateNull(alloc_lists=False):
|
416 | # type: () -> expr.LsAction
|
417 | return expr.LsAction(cast('Optional[str]', None))
|
418 |
|
419 | def PrettyTree(self, do_abbrev, trav=None):
|
420 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
421 | trav = trav or TraversalState()
|
422 | heap_id = id(self)
|
423 | if heap_id in trav.seen:
|
424 | return hnode.AlreadySeen(heap_id)
|
425 | trav.seen[heap_id] = True
|
426 |
|
427 | out_node = NewRecord('expr.LsAction')
|
428 | L = out_node.fields
|
429 |
|
430 | if self.file is not None: # Optional
|
431 | x0 = NewLeaf(self.file, color_e.StringConst)
|
432 | L.append(Field('file', x0))
|
433 |
|
434 | return out_node
|
435 |
|
436 | class ExecAction(expr_t):
|
437 | _type_tag = 14
|
438 | __slots__ = ('batch', 'dir', 'ok', 'argv')
|
439 |
|
440 | def __init__(self, batch, dir, ok, argv):
|
441 | # type: (bool, bool, bool, List[str]) -> None
|
442 | self.batch = batch
|
443 | self.dir = dir
|
444 | self.ok = ok
|
445 | self.argv = argv
|
446 |
|
447 | @staticmethod
|
448 | def CreateNull(alloc_lists=False):
|
449 | # type: () -> expr.ExecAction
|
450 | return expr.ExecAction(False, False, False, [] if alloc_lists else cast('List[str]', None))
|
451 |
|
452 | def PrettyTree(self, do_abbrev, trav=None):
|
453 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
454 | trav = trav or TraversalState()
|
455 | heap_id = id(self)
|
456 | if heap_id in trav.seen:
|
457 | return hnode.AlreadySeen(heap_id)
|
458 | trav.seen[heap_id] = True
|
459 |
|
460 | out_node = NewRecord('expr.ExecAction')
|
461 | L = out_node.fields
|
462 |
|
463 | x0 = hnode.Leaf('T' if self.batch else 'F', color_e.OtherConst)
|
464 | L.append(Field('batch', x0))
|
465 |
|
466 | x1 = hnode.Leaf('T' if self.dir else 'F', color_e.OtherConst)
|
467 | L.append(Field('dir', x1))
|
468 |
|
469 | x2 = hnode.Leaf('T' if self.ok else 'F', color_e.OtherConst)
|
470 | L.append(Field('ok', x2))
|
471 |
|
472 | if self.argv is not None: # List
|
473 | x3 = hnode.Array([])
|
474 | for i3 in self.argv:
|
475 | x3.children.append(NewLeaf(i3, color_e.StringConst))
|
476 | L.append(Field('argv', x3))
|
477 |
|
478 | return out_node
|
479 |
|
480 | pass
|
481 |
|
482 | class pathAccessor_t(pybase.SimpleObj):
|
483 | pass
|
484 |
|
485 | class pathAccessor_e(object):
|
486 | FullPath = pathAccessor_t(1)
|
487 | Filename = pathAccessor_t(2)
|
488 |
|
489 | _pathAccessor_str = {
|
490 | 1: 'FullPath',
|
491 | 2: 'Filename',
|
492 | }
|
493 |
|
494 | def pathAccessor_str(val, dot=True):
|
495 | # type: (pathAccessor_t, bool) -> str
|
496 | v = _pathAccessor_str[val]
|
497 | if dot:
|
498 | return "pathAccessor.%s" % v
|
499 | else:
|
500 | return v
|
501 |
|
502 | class statAccessor_t(pybase.SimpleObj):
|
503 | pass
|
504 |
|
505 | class statAccessor_e(object):
|
506 | AccessTime = statAccessor_t(1)
|
507 | CreationTime = statAccessor_t(2)
|
508 | ModificationTime = statAccessor_t(3)
|
509 | Filesystem = statAccessor_t(4)
|
510 | Inode = statAccessor_t(5)
|
511 | LinkCount = statAccessor_t(6)
|
512 | Mode = statAccessor_t(7)
|
513 | Filetype = statAccessor_t(8)
|
514 | Uid = statAccessor_t(9)
|
515 | Gid = statAccessor_t(10)
|
516 | Username = statAccessor_t(11)
|
517 | Groupname = statAccessor_t(12)
|
518 | Size = statAccessor_t(13)
|
519 |
|
520 | _statAccessor_str = {
|
521 | 1: 'AccessTime',
|
522 | 2: 'CreationTime',
|
523 | 3: 'ModificationTime',
|
524 | 4: 'Filesystem',
|
525 | 5: 'Inode',
|
526 | 6: 'LinkCount',
|
527 | 7: 'Mode',
|
528 | 8: 'Filetype',
|
529 | 9: 'Uid',
|
530 | 10: 'Gid',
|
531 | 11: 'Username',
|
532 | 12: 'Groupname',
|
533 | 13: 'Size',
|
534 | }
|
535 |
|
536 | def statAccessor_str(val, dot=True):
|
537 | # type: (statAccessor_t, bool) -> str
|
538 | v = _statAccessor_str[val]
|
539 | if dot:
|
540 | return "statAccessor.%s" % v
|
541 | else:
|
542 | return v
|
543 |
|
544 | class predicate_e(object):
|
545 | EQ = 1
|
546 | GE = 2
|
547 | LE = 3
|
548 | StringMatch = 4
|
549 | GlobMatch = 5
|
550 | RegexMatch = 6
|
551 | Readable = 7
|
552 | Writable = 8
|
553 | Executable = 9
|
554 |
|
555 | _predicate_str = {
|
556 | 1: 'EQ',
|
557 | 2: 'GE',
|
558 | 3: 'LE',
|
559 | 4: 'StringMatch',
|
560 | 5: 'GlobMatch',
|
561 | 6: 'RegexMatch',
|
562 | 7: 'Readable',
|
563 | 8: 'Writable',
|
564 | 9: 'Executable',
|
565 | }
|
566 |
|
567 | def predicate_str(tag, dot=True):
|
568 | # type: (int, bool) -> str
|
569 | v = _predicate_str[tag]
|
570 | if dot:
|
571 | return "predicate.%s" % v
|
572 | else:
|
573 | return v
|
574 |
|
575 | class predicate_t(pybase.CompoundObj):
|
576 | def tag(self):
|
577 | # type: () -> int
|
578 | return self._type_tag
|
579 |
|
580 | class predicate__Readable(predicate_t):
|
581 | _type_tag = 7
|
582 | __slots__ = ()
|
583 |
|
584 | def __init__(self, ):
|
585 | # type: () -> None
|
586 | pass
|
587 |
|
588 | def PrettyTree(self, do_abbrev, trav=None):
|
589 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
590 | trav = trav or TraversalState()
|
591 | heap_id = id(self)
|
592 | if heap_id in trav.seen:
|
593 | return hnode.AlreadySeen(heap_id)
|
594 | trav.seen[heap_id] = True
|
595 |
|
596 | out_node = NewRecord('predicate.Readable')
|
597 | L = out_node.fields
|
598 |
|
599 | return out_node
|
600 |
|
601 | class predicate__Writable(predicate_t):
|
602 | _type_tag = 8
|
603 | __slots__ = ()
|
604 |
|
605 | def __init__(self, ):
|
606 | # type: () -> None
|
607 | pass
|
608 |
|
609 | def PrettyTree(self, do_abbrev, trav=None):
|
610 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
611 | trav = trav or TraversalState()
|
612 | heap_id = id(self)
|
613 | if heap_id in trav.seen:
|
614 | return hnode.AlreadySeen(heap_id)
|
615 | trav.seen[heap_id] = True
|
616 |
|
617 | out_node = NewRecord('predicate.Writable')
|
618 | L = out_node.fields
|
619 |
|
620 | return out_node
|
621 |
|
622 | class predicate__Executable(predicate_t):
|
623 | _type_tag = 9
|
624 | __slots__ = ()
|
625 |
|
626 | def __init__(self, ):
|
627 | # type: () -> None
|
628 | pass
|
629 |
|
630 | def PrettyTree(self, do_abbrev, trav=None):
|
631 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
632 | trav = trav or TraversalState()
|
633 | heap_id = id(self)
|
634 | if heap_id in trav.seen:
|
635 | return hnode.AlreadySeen(heap_id)
|
636 | trav.seen[heap_id] = True
|
637 |
|
638 | out_node = NewRecord('predicate.Executable')
|
639 | L = out_node.fields
|
640 |
|
641 | return out_node
|
642 |
|
643 | class predicate(object):
|
644 | class EQ(predicate_t):
|
645 | _type_tag = 1
|
646 | __slots__ = ('n',)
|
647 |
|
648 | def __init__(self, n):
|
649 | # type: (int) -> None
|
650 | self.n = n
|
651 |
|
652 | @staticmethod
|
653 | def CreateNull(alloc_lists=False):
|
654 | # type: () -> predicate.EQ
|
655 | return predicate.EQ(-1)
|
656 |
|
657 | def PrettyTree(self, do_abbrev, trav=None):
|
658 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
659 | trav = trav or TraversalState()
|
660 | heap_id = id(self)
|
661 | if heap_id in trav.seen:
|
662 | return hnode.AlreadySeen(heap_id)
|
663 | trav.seen[heap_id] = True
|
664 |
|
665 | out_node = NewRecord('predicate.EQ')
|
666 | L = out_node.fields
|
667 |
|
668 | x0 = hnode.Leaf(str(self.n), color_e.OtherConst)
|
669 | L.append(Field('n', x0))
|
670 |
|
671 | return out_node
|
672 |
|
673 | class GE(predicate_t):
|
674 | _type_tag = 2
|
675 | __slots__ = ('n',)
|
676 |
|
677 | def __init__(self, n):
|
678 | # type: (int) -> None
|
679 | self.n = n
|
680 |
|
681 | @staticmethod
|
682 | def CreateNull(alloc_lists=False):
|
683 | # type: () -> predicate.GE
|
684 | return predicate.GE(-1)
|
685 |
|
686 | def PrettyTree(self, do_abbrev, trav=None):
|
687 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
688 | trav = trav or TraversalState()
|
689 | heap_id = id(self)
|
690 | if heap_id in trav.seen:
|
691 | return hnode.AlreadySeen(heap_id)
|
692 | trav.seen[heap_id] = True
|
693 |
|
694 | out_node = NewRecord('predicate.GE')
|
695 | L = out_node.fields
|
696 |
|
697 | x0 = hnode.Leaf(str(self.n), color_e.OtherConst)
|
698 | L.append(Field('n', x0))
|
699 |
|
700 | return out_node
|
701 |
|
702 | class LE(predicate_t):
|
703 | _type_tag = 3
|
704 | __slots__ = ('n',)
|
705 |
|
706 | def __init__(self, n):
|
707 | # type: (int) -> None
|
708 | self.n = n
|
709 |
|
710 | @staticmethod
|
711 | def CreateNull(alloc_lists=False):
|
712 | # type: () -> predicate.LE
|
713 | return predicate.LE(-1)
|
714 |
|
715 | def PrettyTree(self, do_abbrev, trav=None):
|
716 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
717 | trav = trav or TraversalState()
|
718 | heap_id = id(self)
|
719 | if heap_id in trav.seen:
|
720 | return hnode.AlreadySeen(heap_id)
|
721 | trav.seen[heap_id] = True
|
722 |
|
723 | out_node = NewRecord('predicate.LE')
|
724 | L = out_node.fields
|
725 |
|
726 | x0 = hnode.Leaf(str(self.n), color_e.OtherConst)
|
727 | L.append(Field('n', x0))
|
728 |
|
729 | return out_node
|
730 |
|
731 | class StringMatch(predicate_t):
|
732 | _type_tag = 4
|
733 | __slots__ = ('str', 'ignoreCase')
|
734 |
|
735 | def __init__(self, str, ignoreCase):
|
736 | # type: (str, bool) -> None
|
737 | self.str = str
|
738 | self.ignoreCase = ignoreCase
|
739 |
|
740 | @staticmethod
|
741 | def CreateNull(alloc_lists=False):
|
742 | # type: () -> predicate.StringMatch
|
743 | return predicate.StringMatch('', False)
|
744 |
|
745 | def PrettyTree(self, do_abbrev, trav=None):
|
746 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
747 | trav = trav or TraversalState()
|
748 | heap_id = id(self)
|
749 | if heap_id in trav.seen:
|
750 | return hnode.AlreadySeen(heap_id)
|
751 | trav.seen[heap_id] = True
|
752 |
|
753 | out_node = NewRecord('predicate.StringMatch')
|
754 | L = out_node.fields
|
755 |
|
756 | x0 = NewLeaf(self.str, color_e.StringConst)
|
757 | L.append(Field('str', x0))
|
758 |
|
759 | x1 = hnode.Leaf('T' if self.ignoreCase else 'F', color_e.OtherConst)
|
760 | L.append(Field('ignoreCase', x1))
|
761 |
|
762 | return out_node
|
763 |
|
764 | class GlobMatch(predicate_t):
|
765 | _type_tag = 5
|
766 | __slots__ = ('glob', 'ignoreCase')
|
767 |
|
768 | def __init__(self, glob, ignoreCase):
|
769 | # type: (str, bool) -> None
|
770 | self.glob = glob
|
771 | self.ignoreCase = ignoreCase
|
772 |
|
773 | @staticmethod
|
774 | def CreateNull(alloc_lists=False):
|
775 | # type: () -> predicate.GlobMatch
|
776 | return predicate.GlobMatch('', False)
|
777 |
|
778 | def PrettyTree(self, do_abbrev, trav=None):
|
779 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
780 | trav = trav or TraversalState()
|
781 | heap_id = id(self)
|
782 | if heap_id in trav.seen:
|
783 | return hnode.AlreadySeen(heap_id)
|
784 | trav.seen[heap_id] = True
|
785 |
|
786 | out_node = NewRecord('predicate.GlobMatch')
|
787 | L = out_node.fields
|
788 |
|
789 | x0 = NewLeaf(self.glob, color_e.StringConst)
|
790 | L.append(Field('glob', x0))
|
791 |
|
792 | x1 = hnode.Leaf('T' if self.ignoreCase else 'F', color_e.OtherConst)
|
793 | L.append(Field('ignoreCase', x1))
|
794 |
|
795 | return out_node
|
796 |
|
797 | class RegexMatch(predicate_t):
|
798 | _type_tag = 6
|
799 | __slots__ = ('re', 'ignoreCase')
|
800 |
|
801 | def __init__(self, re, ignoreCase):
|
802 | # type: (str, bool) -> None
|
803 | self.re = re
|
804 | self.ignoreCase = ignoreCase
|
805 |
|
806 | @staticmethod
|
807 | def CreateNull(alloc_lists=False):
|
808 | # type: () -> predicate.RegexMatch
|
809 | return predicate.RegexMatch('', False)
|
810 |
|
811 | def PrettyTree(self, do_abbrev, trav=None):
|
812 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
813 | trav = trav or TraversalState()
|
814 | heap_id = id(self)
|
815 | if heap_id in trav.seen:
|
816 | return hnode.AlreadySeen(heap_id)
|
817 | trav.seen[heap_id] = True
|
818 |
|
819 | out_node = NewRecord('predicate.RegexMatch')
|
820 | L = out_node.fields
|
821 |
|
822 | x0 = NewLeaf(self.re, color_e.StringConst)
|
823 | L.append(Field('re', x0))
|
824 |
|
825 | x1 = hnode.Leaf('T' if self.ignoreCase else 'F', color_e.OtherConst)
|
826 | L.append(Field('ignoreCase', x1))
|
827 |
|
828 | return out_node
|
829 |
|
830 | Readable = predicate__Readable()
|
831 |
|
832 | Writable = predicate__Writable()
|
833 |
|
834 | Executable = predicate__Executable()
|
835 |
|
836 | pass
|
837 |
|