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