OILS / opy / compiler2 / ast.py View on Github | oilshell.org

1332 lines, 1062 significant
1from __future__ import print_function
2import cStringIO
3"""Python abstract syntax node definitions
4
5This file is automatically generated by Tools/compiler/astgen.py
6"""
7from .consts import CO_VARARGS, CO_VARKEYWORDS
8
9# NOTE: Similar to pyassem.flatten().
10def flatten(seq):
11 l = []
12 for elt in seq:
13 if isinstance(elt, (tuple, list)):
14 l.extend(flatten(elt))
15 else:
16 l.append(elt)
17 return l
18
19def flatten_nodes(seq):
20 return [n for n in flatten(seq) if isinstance(n, Node)]
21
22nodes = {}
23
24
25# NOTE: after_equals is a hack to make the output prettier. You could copy
26# _TrySingleLine in asdl/format.py. That took a long time to get right!
27def _PrettyPrint(val, f, indent=0, after_equals=False):
28 indent_str = ' ' * indent
29
30 if isinstance(val, Node):
31 val.PrettyPrint(f, indent=indent, after_equals=after_equals)
32
33 elif isinstance(val, list):
34 if not after_equals:
35 print('%s' % indent_str, end='', file=f)
36 print('[', file=f) # No indent here
37 for item in val:
38 _PrettyPrint(item, f, indent=indent+2)
39 # Not indented as much
40 print('%s]' % indent_str, file=f)
41
42 elif isinstance(val, tuple):
43 if not after_equals:
44 print('%s' % indent_str, end='', file=f)
45 print('(', file=f)
46 for item in val:
47 _PrettyPrint(item, f, indent=indent+2)
48 print('%s)' % indent_str, file=f)
49
50 else:
51 if not after_equals:
52 print('%s' % indent_str, end='', file=f)
53 # String or int?
54 print('%r' % val, file=f)
55
56
57class Node(object):
58 """Abstract base class for ast nodes."""
59
60 ARGNAMES = []
61
62 def getChildren(self):
63 pass # implemented by subclasses
64
65 def __iter__(self):
66 for n in self.getChildren():
67 yield n
68
69 def asList(self): # for backwards compatibility
70 return self.getChildren()
71
72 def getChildNodes(self):
73 pass # implemented by subclasses
74
75 def __repr__(self):
76 f = cStringIO.StringIO()
77 self.PrettyPrint(f)
78 return f.getvalue()
79
80 def PrettyPrint(self, f, indent=0, after_equals=False):
81 indent_str = ' ' * indent
82
83 if not after_equals:
84 print('%s' % indent_str, end='', file=f)
85 print('%s(' % self.__class__.__name__, file=f)
86 for name in self.ARGNAMES:
87 # Print the field name
88 print('%s %s = ' % (indent_str, name), end='', file=f)
89
90 # Print the value
91 val = getattr(self, name)
92
93 _PrettyPrint(val, f, indent=indent+2, after_equals=True)
94
95 print('%s) # %s' % (indent_str, self.__class__.__name__), file=f)
96
97
98class EmptyNode(Node):
99 pass
100
101class Expression(Node):
102 # Expression is an artificial node class to support "eval"
103 nodes["expression"] = "Expression"
104 def __init__(self, node):
105 self.node = node
106
107 def getChildren(self):
108 return self.node,
109
110 def getChildNodes(self):
111 return self.node,
112
113 def __repr__(self):
114 return "Expression(%s)" % (repr(self.node))
115
116class Add(Node):
117 ARGNAMES = ['left', 'right']
118 def __init__(self, leftright, lineno=None):
119 self.left = leftright[0]
120 self.right = leftright[1]
121 self.lineno = lineno
122
123 def getChildren(self):
124 return self.left, self.right
125
126 def getChildNodes(self):
127 return self.left, self.right
128
129class And(Node):
130 ARGNAMES = ['nodes']
131 def __init__(self, nodes, lineno=None):
132 self.nodes = nodes
133 self.lineno = lineno
134
135 def getChildren(self):
136 return tuple(flatten(self.nodes))
137
138 def getChildNodes(self):
139 nodelist = []
140 nodelist.extend(flatten_nodes(self.nodes))
141 return tuple(nodelist)
142
143class AssAttr(Node):
144 ARGNAMES = ['expr', 'attrname', 'flags']
145 def __init__(self, expr, attrname, flags, lineno=None):
146 self.expr = expr
147 self.attrname = attrname
148 self.flags = flags
149 self.lineno = lineno
150
151 def getChildren(self):
152 return self.expr, self.attrname, self.flags
153
154 def getChildNodes(self):
155 return self.expr,
156
157class AssList(Node):
158 ARGNAMES = ['nodes']
159 def __init__(self, nodes, lineno=None):
160 self.nodes = nodes
161 self.lineno = lineno
162
163 def getChildren(self):
164 return tuple(flatten(self.nodes))
165
166 def getChildNodes(self):
167 nodelist = []
168 nodelist.extend(flatten_nodes(self.nodes))
169 return tuple(nodelist)
170
171class AssName(Node):
172 ARGNAMES = ['name', 'flags']
173 def __init__(self, name, flags, lineno=None):
174 self.name = name
175 self.flags = flags
176 self.lineno = lineno
177
178 def getChildren(self):
179 return self.name, self.flags
180
181 def getChildNodes(self):
182 return ()
183
184class AssTuple(Node):
185 ARGNAMES = ['nodes']
186 def __init__(self, nodes, lineno=None):
187 self.nodes = nodes
188 self.lineno = lineno
189
190 def getChildren(self):
191 return tuple(flatten(self.nodes))
192
193 def getChildNodes(self):
194 nodelist = []
195 nodelist.extend(flatten_nodes(self.nodes))
196 return tuple(nodelist)
197
198class Assert(Node):
199 ARGNAMES = ['test', 'fail']
200 def __init__(self, test, fail, lineno=None):
201 self.test = test
202 self.fail = fail
203 self.lineno = lineno
204
205 def getChildren(self):
206 children = []
207 children.append(self.test)
208 children.append(self.fail)
209 return tuple(children)
210
211 def getChildNodes(self):
212 nodelist = []
213 nodelist.append(self.test)
214 if self.fail is not None:
215 nodelist.append(self.fail)
216 return tuple(nodelist)
217
218class Assign(Node):
219 ARGNAMES = ['nodes', 'expr']
220 def __init__(self, nodes, expr, lineno=None):
221 self.nodes = nodes
222 self.expr = expr
223 self.lineno = lineno
224
225 def getChildren(self):
226 children = []
227 children.extend(flatten(self.nodes))
228 children.append(self.expr)
229 return tuple(children)
230
231 def getChildNodes(self):
232 nodelist = []
233 nodelist.extend(flatten_nodes(self.nodes))
234 nodelist.append(self.expr)
235 return tuple(nodelist)
236
237class AugAssign(Node):
238 ARGNAMES = ['node', 'op', 'expr']
239 def __init__(self, node, op, expr, lineno=None):
240 self.node = node
241 self.op = op
242 self.expr = expr
243 self.lineno = lineno
244
245 def getChildren(self):
246 return self.node, self.op, self.expr
247
248 def getChildNodes(self):
249 return self.node, self.expr
250
251class Backquote(Node):
252 ARGNAMES = ['expr']
253 def __init__(self, expr, lineno=None):
254 self.expr = expr
255 self.lineno = lineno
256
257 def getChildren(self):
258 return self.expr,
259
260 def getChildNodes(self):
261 return self.expr,
262
263class Bitand(Node):
264 ARGNAMES = ['nodes']
265 def __init__(self, nodes, lineno=None):
266 self.nodes = nodes
267 self.lineno = lineno
268
269 def getChildren(self):
270 return tuple(flatten(self.nodes))
271
272 def getChildNodes(self):
273 nodelist = []
274 nodelist.extend(flatten_nodes(self.nodes))
275 return tuple(nodelist)
276
277class Bitor(Node):
278 ARGNAMES = ['nodes']
279 def __init__(self, nodes, lineno=None):
280 self.nodes = nodes
281 self.lineno = lineno
282
283 def getChildren(self):
284 return tuple(flatten(self.nodes))
285
286 def getChildNodes(self):
287 nodelist = []
288 nodelist.extend(flatten_nodes(self.nodes))
289 return tuple(nodelist)
290
291class Bitxor(Node):
292 ARGNAMES = ['nodes']
293 def __init__(self, nodes, lineno=None):
294 self.nodes = nodes
295 self.lineno = lineno
296
297 def getChildren(self):
298 return tuple(flatten(self.nodes))
299
300 def getChildNodes(self):
301 nodelist = []
302 nodelist.extend(flatten_nodes(self.nodes))
303 return tuple(nodelist)
304
305class Break(Node):
306 ARGNAMES = []
307 def __init__(self, lineno=None):
308 self.lineno = lineno
309
310 def getChildren(self):
311 return ()
312
313 def getChildNodes(self):
314 return ()
315
316class CallFunc(Node):
317 ARGNAMES = ['node', 'args', 'star_args', 'dstar_args']
318 def __init__(self, node, args, star_args = None, dstar_args = None, lineno=None):
319 self.node = node
320 self.args = args
321 self.star_args = star_args
322 self.dstar_args = dstar_args
323 self.lineno = lineno
324
325 def getChildren(self):
326 children = []
327 children.append(self.node)
328 children.extend(flatten(self.args))
329 children.append(self.star_args)
330 children.append(self.dstar_args)
331 return tuple(children)
332
333 def getChildNodes(self):
334 nodelist = []
335 nodelist.append(self.node)
336 nodelist.extend(flatten_nodes(self.args))
337 if self.star_args is not None:
338 nodelist.append(self.star_args)
339 if self.dstar_args is not None:
340 nodelist.append(self.dstar_args)
341 return tuple(nodelist)
342
343class Class(Node):
344 ARGNAMES = ['name', 'bases', 'doc', 'code', 'decorators']
345 def __init__(self, name, bases, doc, code, decorators = None, lineno=None):
346 self.name = name
347 self.bases = bases
348 self.doc = doc
349 self.code = code
350 self.decorators = decorators
351 self.lineno = lineno
352
353 def getChildren(self):
354 children = []
355 children.append(self.name)
356 children.extend(flatten(self.bases))
357 children.append(self.doc)
358 children.append(self.code)
359 children.append(self.decorators)
360 return tuple(children)
361
362 def getChildNodes(self):
363 nodelist = []
364 nodelist.extend(flatten_nodes(self.bases))
365 nodelist.append(self.code)
366 if self.decorators is not None:
367 nodelist.append(self.decorators)
368 return tuple(nodelist)
369
370class Compare(Node):
371 ARGNAMES = ['expr', 'ops']
372 def __init__(self, expr, ops, lineno=None):
373 self.expr = expr
374 self.ops = ops
375 self.lineno = lineno
376
377 def getChildren(self):
378 children = []
379 children.append(self.expr)
380 children.extend(flatten(self.ops))
381 return tuple(children)
382
383 def getChildNodes(self):
384 nodelist = []
385 nodelist.append(self.expr)
386 nodelist.extend(flatten_nodes(self.ops))
387 return tuple(nodelist)
388
389class Const(Node):
390 ARGNAMES = ['value']
391 def __init__(self, value, lineno=None):
392 self.value = value
393 self.lineno = lineno
394
395 def getChildren(self):
396 return self.value,
397
398 def getChildNodes(self):
399 return ()
400
401class Continue(Node):
402 ARGNAMES = []
403 def __init__(self, lineno=None):
404 self.lineno = lineno
405
406 def getChildren(self):
407 return ()
408
409 def getChildNodes(self):
410 return ()
411
412class Decorators(Node):
413 ARGNAMES = ['nodes']
414 def __init__(self, nodes, lineno=None):
415 self.nodes = nodes
416 self.lineno = lineno
417
418 def getChildren(self):
419 return tuple(flatten(self.nodes))
420
421 def getChildNodes(self):
422 nodelist = []
423 nodelist.extend(flatten_nodes(self.nodes))
424 return tuple(nodelist)
425
426class Dict(Node):
427 ARGNAMES = ['items']
428 def __init__(self, items, lineno=None):
429 self.items = items
430 self.lineno = lineno
431
432 def getChildren(self):
433 return tuple(flatten(self.items))
434
435 def getChildNodes(self):
436 nodelist = []
437 nodelist.extend(flatten_nodes(self.items))
438 return tuple(nodelist)
439
440class DictComp(Node):
441 ARGNAMES = ['key', 'value', 'quals']
442 def __init__(self, key, value, quals, lineno=None):
443 self.key = key
444 self.value = value
445 self.quals = quals
446 self.lineno = lineno
447
448 def getChildren(self):
449 children = []
450 children.append(self.key)
451 children.append(self.value)
452 children.extend(flatten(self.quals))
453 return tuple(children)
454
455 def getChildNodes(self):
456 nodelist = []
457 nodelist.append(self.key)
458 nodelist.append(self.value)
459 nodelist.extend(flatten_nodes(self.quals))
460 return tuple(nodelist)
461
462class Discard(Node):
463 ARGNAMES = ['expr']
464 def __init__(self, expr, lineno=None):
465 self.expr = expr
466 self.lineno = lineno
467
468 def getChildren(self):
469 return self.expr,
470
471 def getChildNodes(self):
472 return self.expr,
473
474class Div(Node):
475 ARGNAMES = ['left', 'right']
476 def __init__(self, leftright, lineno=None):
477 self.left = leftright[0]
478 self.right = leftright[1]
479 self.lineno = lineno
480
481 def getChildren(self):
482 return self.left, self.right
483
484 def getChildNodes(self):
485 return self.left, self.right
486
487class Ellipsis(Node):
488 ARGNAMES = []
489 def __init__(self, lineno=None):
490 self.lineno = lineno
491
492 def getChildren(self):
493 return ()
494
495 def getChildNodes(self):
496 return ()
497
498class Exec(Node):
499 ARGNAMES = ['expr', 'locals', 'globals']
500 def __init__(self, expr, locals, globals, lineno=None):
501 self.expr = expr
502 self.locals = locals
503 self.globals = globals
504 self.lineno = lineno
505
506 def getChildren(self):
507 children = []
508 children.append(self.expr)
509 children.append(self.locals)
510 children.append(self.globals)
511 return tuple(children)
512
513 def getChildNodes(self):
514 nodelist = []
515 nodelist.append(self.expr)
516 if self.locals is not None:
517 nodelist.append(self.locals)
518 if self.globals is not None:
519 nodelist.append(self.globals)
520 return tuple(nodelist)
521
522class FloorDiv(Node):
523 ARGNAMES = ['left', 'right']
524 def __init__(self, leftright, lineno=None):
525 self.left = leftright[0]
526 self.right = leftright[1]
527 self.lineno = lineno
528
529 def getChildren(self):
530 return self.left, self.right
531
532 def getChildNodes(self):
533 return self.left, self.right
534
535class For(Node):
536 ARGNAMES = ['assign', 'list', 'body', 'else_']
537 def __init__(self, assign, list, body, else_, lineno=None):
538 self.assign = assign
539 self.list = list
540 self.body = body
541 self.else_ = else_
542 self.lineno = lineno
543
544 def getChildren(self):
545 children = []
546 children.append(self.assign)
547 children.append(self.list)
548 children.append(self.body)
549 children.append(self.else_)
550 return tuple(children)
551
552 def getChildNodes(self):
553 nodelist = []
554 nodelist.append(self.assign)
555 nodelist.append(self.list)
556 nodelist.append(self.body)
557 if self.else_ is not None:
558 nodelist.append(self.else_)
559 return tuple(nodelist)
560
561class From(Node):
562 ARGNAMES = ['modname', 'names', 'level']
563 def __init__(self, modname, names, level, lineno=None):
564 self.modname = modname
565 self.names = names
566 self.level = level
567 self.lineno = lineno
568
569 def getChildren(self):
570 return self.modname, self.names, self.level
571
572 def getChildNodes(self):
573 return ()
574
575class Function(Node):
576 ARGNAMES = ['decorators', 'name', 'argnames', 'defaults', 'flags', 'doc', 'code']
577 def __init__(self, decorators, name, argnames, defaults, flags, doc, code, lineno=None):
578 self.decorators = decorators
579 self.name = name
580 self.argnames = argnames
581 self.defaults = defaults
582 self.flags = flags
583 self.doc = doc
584 self.code = code
585 self.lineno = lineno
586 self.varargs = self.kwargs = None
587 if flags & CO_VARARGS:
588 self.varargs = 1
589 if flags & CO_VARKEYWORDS:
590 self.kwargs = 1
591
592
593 def getChildren(self):
594 children = []
595 children.append(self.decorators)
596 children.append(self.name)
597 children.append(self.argnames)
598 children.extend(flatten(self.defaults))
599 children.append(self.flags)
600 children.append(self.doc)
601 children.append(self.code)
602 return tuple(children)
603
604 def getChildNodes(self):
605 nodelist = []
606 if self.decorators is not None:
607 nodelist.append(self.decorators)
608 nodelist.extend(flatten_nodes(self.defaults))
609 nodelist.append(self.code)
610 return tuple(nodelist)
611
612class GenExpr(Node):
613 ARGNAMES = ['code']
614 def __init__(self, code, lineno=None):
615 self.code = code
616 self.lineno = lineno
617 self.argnames = ['.0']
618 self.varargs = self.kwargs = None
619
620
621 def getChildren(self):
622 return self.code,
623
624 def getChildNodes(self):
625 return self.code,
626
627class GenExprFor(Node):
628 ARGNAMES = ['assign', 'iter', 'ifs']
629 def __init__(self, assign, iter, ifs, lineno=None):
630 self.assign = assign
631 self.iter = iter
632 self.ifs = ifs
633 self.lineno = lineno
634 self.is_outmost = False
635
636 def getChildren(self):
637 children = []
638 children.append(self.assign)
639 children.append(self.iter)
640 children.extend(flatten(self.ifs))
641 return tuple(children)
642
643 def getChildNodes(self):
644 nodelist = []
645 nodelist.append(self.assign)
646 nodelist.append(self.iter)
647 nodelist.extend(flatten_nodes(self.ifs))
648 return tuple(nodelist)
649
650class GenExprIf(Node):
651 ARGNAMES = ['test']
652 def __init__(self, test, lineno=None):
653 self.test = test
654 self.lineno = lineno
655
656 def getChildren(self):
657 return self.test,
658
659 def getChildNodes(self):
660 return self.test,
661
662class GenExprInner(Node):
663 ARGNAMES = ['expr', 'quals']
664 def __init__(self, expr, quals, lineno=None):
665 self.expr = expr
666 self.quals = quals
667 self.lineno = lineno
668
669 def getChildren(self):
670 children = []
671 children.append(self.expr)
672 children.extend(flatten(self.quals))
673 return tuple(children)
674
675 def getChildNodes(self):
676 nodelist = []
677 nodelist.append(self.expr)
678 nodelist.extend(flatten_nodes(self.quals))
679 return tuple(nodelist)
680
681class Getattr(Node):
682 ARGNAMES = ['expr', 'attrname']
683 def __init__(self, expr, attrname, lineno=None):
684 self.expr = expr
685 self.attrname = attrname
686 self.lineno = lineno
687
688 def getChildren(self):
689 return self.expr, self.attrname
690
691 def getChildNodes(self):
692 return self.expr,
693
694class Global(Node):
695 ARGNAMES = ['names']
696 def __init__(self, names, lineno=None):
697 self.names = names
698 self.lineno = lineno
699
700 def getChildren(self):
701 return self.names,
702
703 def getChildNodes(self):
704 return ()
705
706class If(Node):
707 ARGNAMES = ['tests', 'else_']
708 def __init__(self, tests, else_, lineno=None):
709 self.tests = tests
710 self.else_ = else_
711 self.lineno = lineno
712
713 def getChildren(self):
714 children = []
715 children.extend(flatten(self.tests))
716 children.append(self.else_)
717 return tuple(children)
718
719 def getChildNodes(self):
720 nodelist = []
721 nodelist.extend(flatten_nodes(self.tests))
722 if self.else_ is not None:
723 nodelist.append(self.else_)
724 return tuple(nodelist)
725
726class IfExp(Node):
727 ARGNAMES = ['test', 'then', 'else_']
728 def __init__(self, test, then, else_, lineno=None):
729 self.test = test
730 self.then = then
731 self.else_ = else_
732 self.lineno = lineno
733
734 def getChildren(self):
735 return self.test, self.then, self.else_
736
737 def getChildNodes(self):
738 return self.test, self.then, self.else_
739
740class Import(Node):
741 ARGNAMES = ['names']
742 def __init__(self, names, lineno=None):
743 self.names = names
744 self.lineno = lineno
745
746 def getChildren(self):
747 return self.names,
748
749 def getChildNodes(self):
750 return ()
751
752class Invert(Node):
753 ARGNAMES = ['expr']
754 def __init__(self, expr, lineno=None):
755 self.expr = expr
756 self.lineno = lineno
757
758 def getChildren(self):
759 return self.expr,
760
761 def getChildNodes(self):
762 return self.expr,
763
764class Keyword(Node):
765 ARGNAMES = ['name', 'expr']
766 def __init__(self, name, expr, lineno=None):
767 self.name = name
768 self.expr = expr
769 self.lineno = lineno
770
771 def getChildren(self):
772 return self.name, self.expr
773
774 def getChildNodes(self):
775 return self.expr,
776
777class Lambda(Node):
778 ARGNAMES = ['argnames', 'defaults', 'flags', 'code']
779 def __init__(self, argnames, defaults, flags, code, lineno=None):
780 self.argnames = argnames
781 self.defaults = defaults
782 self.flags = flags
783 self.code = code
784 self.lineno = lineno
785 self.varargs = self.kwargs = None
786 if flags & CO_VARARGS:
787 self.varargs = 1
788 if flags & CO_VARKEYWORDS:
789 self.kwargs = 1
790
791
792 def getChildren(self):
793 children = []
794 children.append(self.argnames)
795 children.extend(flatten(self.defaults))
796 children.append(self.flags)
797 children.append(self.code)
798 return tuple(children)
799
800 def getChildNodes(self):
801 nodelist = []
802 nodelist.extend(flatten_nodes(self.defaults))
803 nodelist.append(self.code)
804 return tuple(nodelist)
805
806class LeftShift(Node):
807 ARGNAMES = ['left', 'right']
808 def __init__(self, leftright, lineno=None):
809 self.left = leftright[0]
810 self.right = leftright[1]
811 self.lineno = lineno
812
813 def getChildren(self):
814 return self.left, self.right
815
816 def getChildNodes(self):
817 return self.left, self.right
818
819class List(Node):
820 ARGNAMES = ['nodes']
821 def __init__(self, nodes, lineno=None):
822 self.nodes = nodes
823 self.lineno = lineno
824
825 def getChildren(self):
826 return tuple(flatten(self.nodes))
827
828 def getChildNodes(self):
829 nodelist = []
830 nodelist.extend(flatten_nodes(self.nodes))
831 return tuple(nodelist)
832
833class ListComp(Node):
834 ARGNAMES = ['expr', 'quals']
835 def __init__(self, expr, quals, lineno=None):
836 self.expr = expr
837 self.quals = quals
838 self.lineno = lineno
839
840 def getChildren(self):
841 children = []
842 children.append(self.expr)
843 children.extend(flatten(self.quals))
844 return tuple(children)
845
846 def getChildNodes(self):
847 nodelist = []
848 nodelist.append(self.expr)
849 nodelist.extend(flatten_nodes(self.quals))
850 return tuple(nodelist)
851
852class ListCompFor(Node):
853 ARGNAMES = ['assign', 'list', 'ifs']
854 def __init__(self, assign, list, ifs, lineno=None):
855 self.assign = assign
856 self.list = list
857 self.ifs = ifs
858 self.lineno = lineno
859
860 def getChildren(self):
861 children = []
862 children.append(self.assign)
863 children.append(self.list)
864 children.extend(flatten(self.ifs))
865 return tuple(children)
866
867 def getChildNodes(self):
868 nodelist = []
869 nodelist.append(self.assign)
870 nodelist.append(self.list)
871 nodelist.extend(flatten_nodes(self.ifs))
872 return tuple(nodelist)
873
874class ListCompIf(Node):
875 ARGNAMES = ['test']
876 def __init__(self, test, lineno=None):
877 self.test = test
878 self.lineno = lineno
879
880 def getChildren(self):
881 return self.test,
882
883 def getChildNodes(self):
884 return self.test,
885
886class Mod(Node):
887 ARGNAMES = ['left', 'right']
888 def __init__(self, leftright, lineno=None):
889 self.left = leftright[0]
890 self.right = leftright[1]
891 self.lineno = lineno
892
893 def getChildren(self):
894 return self.left, self.right
895
896 def getChildNodes(self):
897 return self.left, self.right
898
899class Module(Node):
900 ARGNAMES = ['doc', 'node']
901 def __init__(self, doc, node, lineno=None):
902 self.doc = doc
903 self.node = node
904 self.lineno = lineno
905
906 def getChildren(self):
907 return self.doc, self.node
908
909 def getChildNodes(self):
910 return self.node,
911
912class Mul(Node):
913 ARGNAMES = ['left', 'right']
914 def __init__(self, leftright, lineno=None):
915 self.left = leftright[0]
916 self.right = leftright[1]
917 self.lineno = lineno
918
919 def getChildren(self):
920 return self.left, self.right
921
922 def getChildNodes(self):
923 return self.left, self.right
924
925class Name(Node):
926 ARGNAMES = ['name']
927 def __init__(self, name, lineno=None):
928 self.name = name
929 self.lineno = lineno
930
931 def getChildren(self):
932 return self.name,
933
934 def getChildNodes(self):
935 return ()
936
937class Not(Node):
938 ARGNAMES = ['expr']
939 def __init__(self, expr, lineno=None):
940 self.expr = expr
941 self.lineno = lineno
942
943 def getChildren(self):
944 return self.expr,
945
946 def getChildNodes(self):
947 return self.expr,
948
949class Or(Node):
950 ARGNAMES = ['nodes']
951 def __init__(self, nodes, lineno=None):
952 self.nodes = nodes
953 self.lineno = lineno
954
955 def getChildren(self):
956 return tuple(flatten(self.nodes))
957
958 def getChildNodes(self):
959 nodelist = []
960 nodelist.extend(flatten_nodes(self.nodes))
961 return tuple(nodelist)
962
963class Pass(Node):
964 ARGNAMES = []
965 def __init__(self, lineno=None):
966 self.lineno = lineno
967
968 def getChildren(self):
969 return ()
970
971 def getChildNodes(self):
972 return ()
973
974class Power(Node):
975 ARGNAMES = ['left', 'right']
976 def __init__(self, leftright, lineno=None):
977 self.left = leftright[0]
978 self.right = leftright[1]
979 self.lineno = lineno
980
981 def getChildren(self):
982 return self.left, self.right
983
984 def getChildNodes(self):
985 return self.left, self.right
986
987class Print(Node):
988 ARGNAMES = ['nodes', 'dest']
989 def __init__(self, nodes, dest, lineno=None):
990 self.nodes = nodes
991 self.dest = dest
992 self.lineno = lineno
993
994 def getChildren(self):
995 children = []
996 children.extend(flatten(self.nodes))
997 children.append(self.dest)
998 return tuple(children)
999
1000 def getChildNodes(self):
1001 nodelist = []
1002 nodelist.extend(flatten_nodes(self.nodes))
1003 if self.dest is not None:
1004 nodelist.append(self.dest)
1005 return tuple(nodelist)
1006
1007class Printnl(Node):
1008 ARGNAMES = ['nodes', 'dest']
1009 def __init__(self, nodes, dest, lineno=None):
1010 self.nodes = nodes
1011 self.dest = dest
1012 self.lineno = lineno
1013
1014 def getChildren(self):
1015 children = []
1016 children.extend(flatten(self.nodes))
1017 children.append(self.dest)
1018 return tuple(children)
1019
1020 def getChildNodes(self):
1021 nodelist = []
1022 nodelist.extend(flatten_nodes(self.nodes))
1023 if self.dest is not None:
1024 nodelist.append(self.dest)
1025 return tuple(nodelist)
1026
1027class Raise(Node):
1028 ARGNAMES = ['expr1', 'expr2', 'expr3']
1029 def __init__(self, expr1, expr2, expr3, lineno=None):
1030 self.expr1 = expr1
1031 self.expr2 = expr2
1032 self.expr3 = expr3
1033 self.lineno = lineno
1034
1035 def getChildren(self):
1036 children = []
1037 children.append(self.expr1)
1038 children.append(self.expr2)
1039 children.append(self.expr3)
1040 return tuple(children)
1041
1042 def getChildNodes(self):
1043 nodelist = []
1044 if self.expr1 is not None:
1045 nodelist.append(self.expr1)
1046 if self.expr2 is not None:
1047 nodelist.append(self.expr2)
1048 if self.expr3 is not None:
1049 nodelist.append(self.expr3)
1050 return tuple(nodelist)
1051
1052class Return(Node):
1053 ARGNAMES = ['value']
1054 def __init__(self, value, lineno=None):
1055 self.value = value
1056 self.lineno = lineno
1057
1058 def getChildren(self):
1059 return self.value,
1060
1061 def getChildNodes(self):
1062 return self.value,
1063
1064class RightShift(Node):
1065 ARGNAMES = ['left', 'right']
1066 def __init__(self, leftright, lineno=None):
1067 self.left = leftright[0]
1068 self.right = leftright[1]
1069 self.lineno = lineno
1070
1071 def getChildren(self):
1072 return self.left, self.right
1073
1074 def getChildNodes(self):
1075 return self.left, self.right
1076
1077class Set(Node):
1078 ARGNAMES = ['nodes']
1079 def __init__(self, nodes, lineno=None):
1080 self.nodes = nodes
1081 self.lineno = lineno
1082
1083 def getChildren(self):
1084 return tuple(flatten(self.nodes))
1085
1086 def getChildNodes(self):
1087 nodelist = []
1088 nodelist.extend(flatten_nodes(self.nodes))
1089 return tuple(nodelist)
1090
1091class SetComp(Node):
1092 ARGNAMES = ['expr', 'quals']
1093 def __init__(self, expr, quals, lineno=None):
1094 self.expr = expr
1095 self.quals = quals
1096 self.lineno = lineno
1097
1098 def getChildren(self):
1099 children = []
1100 children.append(self.expr)
1101 children.extend(flatten(self.quals))
1102 return tuple(children)
1103
1104 def getChildNodes(self):
1105 nodelist = []
1106 nodelist.append(self.expr)
1107 nodelist.extend(flatten_nodes(self.quals))
1108 return tuple(nodelist)
1109
1110class Slice(Node):
1111 ARGNAMES = ['expr', 'flags', 'lower', 'upper']
1112 def __init__(self, expr, flags, lower, upper, lineno=None):
1113 self.expr = expr
1114 self.flags = flags
1115 self.lower = lower
1116 self.upper = upper
1117 self.lineno = lineno
1118
1119 def getChildren(self):
1120 children = []
1121 children.append(self.expr)
1122 children.append(self.flags)
1123 children.append(self.lower)
1124 children.append(self.upper)
1125 return tuple(children)
1126
1127 def getChildNodes(self):
1128 nodelist = []
1129 nodelist.append(self.expr)
1130 if self.lower is not None:
1131 nodelist.append(self.lower)
1132 if self.upper is not None:
1133 nodelist.append(self.upper)
1134 return tuple(nodelist)
1135
1136class Sliceobj(Node):
1137 ARGNAMES = ['nodes']
1138 def __init__(self, nodes, lineno=None):
1139 self.nodes = nodes
1140 self.lineno = lineno
1141
1142 def getChildren(self):
1143 return tuple(flatten(self.nodes))
1144
1145 def getChildNodes(self):
1146 nodelist = []
1147 nodelist.extend(flatten_nodes(self.nodes))
1148 return tuple(nodelist)
1149
1150class Stmt(Node):
1151 ARGNAMES = ['nodes']
1152 def __init__(self, nodes, lineno=None):
1153 self.nodes = nodes
1154 self.lineno = lineno
1155
1156 def getChildren(self):
1157 return tuple(flatten(self.nodes))
1158
1159 def getChildNodes(self):
1160 nodelist = []
1161 nodelist.extend(flatten_nodes(self.nodes))
1162 return tuple(nodelist)
1163
1164class Sub(Node):
1165 ARGNAMES = ['left', 'right']
1166 def __init__(self, leftright, lineno=None):
1167 self.left = leftright[0]
1168 self.right = leftright[1]
1169 self.lineno = lineno
1170
1171 def getChildren(self):
1172 return self.left, self.right
1173
1174 def getChildNodes(self):
1175 return self.left, self.right
1176
1177class Subscript(Node):
1178 ARGNAMES = ['expr', 'flags', 'subs']
1179 def __init__(self, expr, flags, subs, lineno=None):
1180 self.expr = expr
1181 self.flags = flags
1182 self.subs = subs
1183 self.lineno = lineno
1184
1185 def getChildren(self):
1186 children = []
1187 children.append(self.expr)
1188 children.append(self.flags)
1189 children.extend(flatten(self.subs))
1190 return tuple(children)
1191
1192 def getChildNodes(self):
1193 nodelist = []
1194 nodelist.append(self.expr)
1195 nodelist.extend(flatten_nodes(self.subs))
1196 return tuple(nodelist)
1197
1198class TryExcept(Node):
1199 ARGNAMES = ['body', 'handlers', 'else_']
1200 def __init__(self, body, handlers, else_, lineno=None):
1201 self.body = body
1202 self.handlers = handlers
1203 self.else_ = else_
1204 self.lineno = lineno
1205
1206 def getChildren(self):
1207 children = []
1208 children.append(self.body)
1209 children.extend(flatten(self.handlers))
1210 children.append(self.else_)
1211 return tuple(children)
1212
1213 def getChildNodes(self):
1214 nodelist = []
1215 nodelist.append(self.body)
1216 nodelist.extend(flatten_nodes(self.handlers))
1217 if self.else_ is not None:
1218 nodelist.append(self.else_)
1219 return tuple(nodelist)
1220
1221class TryFinally(Node):
1222 ARGNAMES = ['body', 'final']
1223 def __init__(self, body, final, lineno=None):
1224 self.body = body
1225 self.final = final
1226 self.lineno = lineno
1227
1228 def getChildren(self):
1229 return self.body, self.final
1230
1231 def getChildNodes(self):
1232 return self.body, self.final
1233
1234class Tuple(Node):
1235 ARGNAMES = ['nodes']
1236 def __init__(self, nodes, lineno=None):
1237 self.nodes = nodes
1238 self.lineno = lineno
1239
1240 def getChildren(self):
1241 return tuple(flatten(self.nodes))
1242
1243 def getChildNodes(self):
1244 nodelist = []
1245 nodelist.extend(flatten_nodes(self.nodes))
1246 return tuple(nodelist)
1247
1248class UnaryAdd(Node):
1249 ARGNAMES = ['expr']
1250 def __init__(self, expr, lineno=None):
1251 self.expr = expr
1252 self.lineno = lineno
1253
1254 def getChildren(self):
1255 return self.expr,
1256
1257 def getChildNodes(self):
1258 return self.expr,
1259
1260class UnarySub(Node):
1261 ARGNAMES = ['expr']
1262 def __init__(self, expr, lineno=None):
1263 self.expr = expr
1264 self.lineno = lineno
1265
1266 def getChildren(self):
1267 return self.expr,
1268
1269 def getChildNodes(self):
1270 return self.expr,
1271
1272class While(Node):
1273 ARGNAMES = ['test', 'body', 'else_']
1274 def __init__(self, test, body, else_, lineno=None):
1275 self.test = test
1276 self.body = body
1277 self.else_ = else_
1278 self.lineno = lineno
1279
1280 def getChildren(self):
1281 children = []
1282 children.append(self.test)
1283 children.append(self.body)
1284 children.append(self.else_)
1285 return tuple(children)
1286
1287 def getChildNodes(self):
1288 nodelist = []
1289 nodelist.append(self.test)
1290 nodelist.append(self.body)
1291 if self.else_ is not None:
1292 nodelist.append(self.else_)
1293 return tuple(nodelist)
1294
1295class With(Node):
1296 ARGNAMES = ['expr', 'vars', 'body']
1297 def __init__(self, expr, vars, body, lineno=None):
1298 self.expr = expr
1299 self.vars = vars
1300 self.body = body
1301 self.lineno = lineno
1302
1303 def getChildren(self):
1304 children = []
1305 children.append(self.expr)
1306 children.append(self.vars)
1307 children.append(self.body)
1308 return tuple(children)
1309
1310 def getChildNodes(self):
1311 nodelist = []
1312 nodelist.append(self.expr)
1313 if self.vars is not None:
1314 nodelist.append(self.vars)
1315 nodelist.append(self.body)
1316 return tuple(nodelist)
1317
1318class Yield(Node):
1319 ARGNAMES = ['value']
1320 def __init__(self, value, lineno=None):
1321 self.value = value
1322 self.lineno = lineno
1323
1324 def getChildren(self):
1325 return self.value,
1326
1327 def getChildNodes(self):
1328 return self.value,
1329
1330for name, obj in globals().items():
1331 if isinstance(obj, type) and issubclass(obj, Node):
1332 nodes[name.lower()] = obj