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