1#----------------------------------------------------------------- 2# ** ATTENTION ** 3# This code was automatically generated from the file: 4# _c_ast.cfg 5# 6# Do not modify it directly. Modify the configuration file and 7# run the generator again. 8# ** ** *** ** ** 9# 10# pycparser: c_ast.py 11# 12# AST Node classes. 13# 14# Eli Bendersky [https://eli.thegreenplace.net/] 15# License: BSD 16#----------------------------------------------------------------- 17 18 19import sys 20 21def _repr(obj): 22 """ 23 Get the representation of an object, with dedicated pprint-like format for lists. 24 """ 25 if isinstance(obj, list): 26 return '[' + (',\n '.join((_repr(e).replace('\n', '\n ') for e in obj))) + '\n]' 27 else: 28 return repr(obj) 29 30class Node(object): 31 __slots__ = () 32 """ Abstract base class for AST nodes. 33 """ 34 def __repr__(self): 35 """ Generates a python representation of the current node 36 """ 37 result = self.__class__.__name__ + '(' 38 39 indent = '' 40 separator = '' 41 for name in self.__slots__[:-2]: 42 result += separator 43 result += indent 44 result += name + '=' + (_repr(getattr(self, name)).replace('\n', '\n ' + (' ' * (len(name) + len(self.__class__.__name__))))) 45 46 separator = ',' 47 indent = '\n ' + (' ' * len(self.__class__.__name__)) 48 49 result += indent + ')' 50 51 return result 52 53 def children(self): 54 """ A sequence of all children that are Nodes 55 """ 56 pass 57 58 def show(self, buf=sys.stdout, offset=0, attrnames=False, nodenames=False, showcoord=False, _my_node_name=None): 59 """ Pretty print the Node and all its attributes and 60 children (recursively) to a buffer. 61 62 buf: 63 Open IO buffer into which the Node is printed. 64 65 offset: 66 Initial offset (amount of leading spaces) 67 68 attrnames: 69 True if you want to see the attribute names in 70 name=value pairs. False to only see the values. 71 72 nodenames: 73 True if you want to see the actual node names 74 within their parents. 75 76 showcoord: 77 Do you want the coordinates of each Node to be 78 displayed. 79 """ 80 lead = ' ' * offset 81 if nodenames and _my_node_name is not None: 82 buf.write(lead + self.__class__.__name__+ ' <' + _my_node_name + '>: ') 83 else: 84 buf.write(lead + self.__class__.__name__+ ': ') 85 86 if self.attr_names: 87 if attrnames: 88 nvlist = [(n, getattr(self,n)) for n in self.attr_names] 89 attrstr = ', '.join('%s=%s' % nv for nv in nvlist) 90 else: 91 vlist = [getattr(self, n) for n in self.attr_names] 92 attrstr = ', '.join('%s' % v for v in vlist) 93 buf.write(attrstr) 94 95 if showcoord: 96 buf.write(' (at %s)' % self.coord) 97 buf.write('\n') 98 99 for (child_name, child) in self.children(): 100 child.show( 101 buf, 102 offset=offset + 2, 103 attrnames=attrnames, 104 nodenames=nodenames, 105 showcoord=showcoord, 106 _my_node_name=child_name) 107 108 109class NodeVisitor(object): 110 """ A base NodeVisitor class for visiting c_ast nodes. 111 Subclass it and define your own visit_XXX methods, where 112 XXX is the class name you want to visit with these 113 methods. 114 115 For example: 116 117 class ConstantVisitor(NodeVisitor): 118 def __init__(self): 119 self.values = [] 120 121 def visit_Constant(self, node): 122 self.values.append(node.value) 123 124 Creates a list of values of all the constant nodes 125 encountered below the given node. To use it: 126 127 cv = ConstantVisitor() 128 cv.visit(node) 129 130 Notes: 131 132 * generic_visit() will be called for AST nodes for which 133 no visit_XXX method was defined. 134 * The children of nodes for which a visit_XXX was 135 defined will not be visited - if you need this, call 136 generic_visit() on the node. 137 You can use: 138 NodeVisitor.generic_visit(self, node) 139 * Modeled after Python's own AST visiting facilities 140 (the ast module of Python 3.0) 141 """ 142 143 _method_cache = None 144 145 def visit(self, node): 146 """ Visit a node. 147 """ 148 149 if self._method_cache is None: 150 self._method_cache = {} 151 152 visitor = self._method_cache.get(node.__class__.__name__, None) 153 if visitor is None: 154 method = 'visit_' + node.__class__.__name__ 155 visitor = getattr(self, method, self.generic_visit) 156 self._method_cache[node.__class__.__name__] = visitor 157 158 return visitor(node) 159 160 def generic_visit(self, node): 161 """ Called if no explicit visitor function exists for a 162 node. Implements preorder visiting of the node. 163 """ 164 for c in node: 165 self.visit(c) 166 167class ArrayDecl(Node): 168 __slots__ = ('type', 'dim', 'dim_quals', 'coord', '__weakref__') 169 def __init__(self, type, dim, dim_quals, coord=None): 170 self.type = type 171 self.dim = dim 172 self.dim_quals = dim_quals 173 self.coord = coord 174 175 def children(self): 176 nodelist = [] 177 if self.type is not None: nodelist.append(("type", self.type)) 178 if self.dim is not None: nodelist.append(("dim", self.dim)) 179 return tuple(nodelist) 180 181 def __iter__(self): 182 if self.type is not None: 183 yield self.type 184 if self.dim is not None: 185 yield self.dim 186 187 attr_names = ('dim_quals', ) 188 189class ArrayRef(Node): 190 __slots__ = ('name', 'subscript', 'coord', '__weakref__') 191 def __init__(self, name, subscript, coord=None): 192 self.name = name 193 self.subscript = subscript 194 self.coord = coord 195 196 def children(self): 197 nodelist = [] 198 if self.name is not None: nodelist.append(("name", self.name)) 199 if self.subscript is not None: nodelist.append(("subscript", self.subscript)) 200 return tuple(nodelist) 201 202 def __iter__(self): 203 if self.name is not None: 204 yield self.name 205 if self.subscript is not None: 206 yield self.subscript 207 208 attr_names = () 209 210class Assignment(Node): 211 __slots__ = ('op', 'lvalue', 'rvalue', 'coord', '__weakref__') 212 def __init__(self, op, lvalue, rvalue, coord=None): 213 self.op = op 214 self.lvalue = lvalue 215 self.rvalue = rvalue 216 self.coord = coord 217 218 def children(self): 219 nodelist = [] 220 if self.lvalue is not None: nodelist.append(("lvalue", self.lvalue)) 221 if self.rvalue is not None: nodelist.append(("rvalue", self.rvalue)) 222 return tuple(nodelist) 223 224 def __iter__(self): 225 if self.lvalue is not None: 226 yield self.lvalue 227 if self.rvalue is not None: 228 yield self.rvalue 229 230 attr_names = ('op', ) 231 232class BinaryOp(Node): 233 __slots__ = ('op', 'left', 'right', 'coord', '__weakref__') 234 def __init__(self, op, left, right, coord=None): 235 self.op = op 236 self.left = left 237 self.right = right 238 self.coord = coord 239 240 def children(self): 241 nodelist = [] 242 if self.left is not None: nodelist.append(("left", self.left)) 243 if self.right is not None: nodelist.append(("right", self.right)) 244 return tuple(nodelist) 245 246 def __iter__(self): 247 if self.left is not None: 248 yield self.left 249 if self.right is not None: 250 yield self.right 251 252 attr_names = ('op', ) 253 254class Break(Node): 255 __slots__ = ('coord', '__weakref__') 256 def __init__(self, coord=None): 257 self.coord = coord 258 259 def children(self): 260 return () 261 262 def __iter__(self): 263 return 264 yield 265 266 attr_names = () 267 268class Case(Node): 269 __slots__ = ('expr', 'stmts', 'coord', '__weakref__') 270 def __init__(self, expr, stmts, coord=None): 271 self.expr = expr 272 self.stmts = stmts 273 self.coord = coord 274 275 def children(self): 276 nodelist = [] 277 if self.expr is not None: nodelist.append(("expr", self.expr)) 278 for i, child in enumerate(self.stmts or []): 279 nodelist.append(("stmts[%d]" % i, child)) 280 return tuple(nodelist) 281 282 def __iter__(self): 283 if self.expr is not None: 284 yield self.expr 285 for child in (self.stmts or []): 286 yield child 287 288 attr_names = () 289 290class Cast(Node): 291 __slots__ = ('to_type', 'expr', 'coord', '__weakref__') 292 def __init__(self, to_type, expr, coord=None): 293 self.to_type = to_type 294 self.expr = expr 295 self.coord = coord 296 297 def children(self): 298 nodelist = [] 299 if self.to_type is not None: nodelist.append(("to_type", self.to_type)) 300 if self.expr is not None: nodelist.append(("expr", self.expr)) 301 return tuple(nodelist) 302 303 def __iter__(self): 304 if self.to_type is not None: 305 yield self.to_type 306 if self.expr is not None: 307 yield self.expr 308 309 attr_names = () 310 311class Compound(Node): 312 __slots__ = ('block_items', 'coord', '__weakref__') 313 def __init__(self, block_items, coord=None): 314 self.block_items = block_items 315 self.coord = coord 316 317 def children(self): 318 nodelist = [] 319 for i, child in enumerate(self.block_items or []): 320 nodelist.append(("block_items[%d]" % i, child)) 321 return tuple(nodelist) 322 323 def __iter__(self): 324 for child in (self.block_items or []): 325 yield child 326 327 attr_names = () 328 329class CompoundLiteral(Node): 330 __slots__ = ('type', 'init', 'coord', '__weakref__') 331 def __init__(self, type, init, coord=None): 332 self.type = type 333 self.init = init 334 self.coord = coord 335 336 def children(self): 337 nodelist = [] 338 if self.type is not None: nodelist.append(("type", self.type)) 339 if self.init is not None: nodelist.append(("init", self.init)) 340 return tuple(nodelist) 341 342 def __iter__(self): 343 if self.type is not None: 344 yield self.type 345 if self.init is not None: 346 yield self.init 347 348 attr_names = () 349 350class Constant(Node): 351 __slots__ = ('type', 'value', 'coord', '__weakref__') 352 def __init__(self, type, value, coord=None): 353 self.type = type 354 self.value = value 355 self.coord = coord 356 357 def children(self): 358 nodelist = [] 359 return tuple(nodelist) 360 361 def __iter__(self): 362 return 363 yield 364 365 attr_names = ('type', 'value', ) 366 367class Continue(Node): 368 __slots__ = ('coord', '__weakref__') 369 def __init__(self, coord=None): 370 self.coord = coord 371 372 def children(self): 373 return () 374 375 def __iter__(self): 376 return 377 yield 378 379 attr_names = () 380 381class Decl(Node): 382 __slots__ = ('name', 'quals', 'storage', 'funcspec', 'type', 'init', 'bitsize', 'coord', '__weakref__') 383 def __init__(self, name, quals, storage, funcspec, type, init, bitsize, coord=None): 384 self.name = name 385 self.quals = quals 386 self.storage = storage 387 self.funcspec = funcspec 388 self.type = type 389 self.init = init 390 self.bitsize = bitsize 391 self.coord = coord 392 393 def children(self): 394 nodelist = [] 395 if self.type is not None: nodelist.append(("type", self.type)) 396 if self.init is not None: nodelist.append(("init", self.init)) 397 if self.bitsize is not None: nodelist.append(("bitsize", self.bitsize)) 398 return tuple(nodelist) 399 400 def __iter__(self): 401 if self.type is not None: 402 yield self.type 403 if self.init is not None: 404 yield self.init 405 if self.bitsize is not None: 406 yield self.bitsize 407 408 attr_names = ('name', 'quals', 'storage', 'funcspec', ) 409 410class DeclList(Node): 411 __slots__ = ('decls', 'coord', '__weakref__') 412 def __init__(self, decls, coord=None): 413 self.decls = decls 414 self.coord = coord 415 416 def children(self): 417 nodelist = [] 418 for i, child in enumerate(self.decls or []): 419 nodelist.append(("decls[%d]" % i, child)) 420 return tuple(nodelist) 421 422 def __iter__(self): 423 for child in (self.decls or []): 424 yield child 425 426 attr_names = () 427 428class Default(Node): 429 __slots__ = ('stmts', 'coord', '__weakref__') 430 def __init__(self, stmts, coord=None): 431 self.stmts = stmts 432 self.coord = coord 433 434 def children(self): 435 nodelist = [] 436 for i, child in enumerate(self.stmts or []): 437 nodelist.append(("stmts[%d]" % i, child)) 438 return tuple(nodelist) 439 440 def __iter__(self): 441 for child in (self.stmts or []): 442 yield child 443 444 attr_names = () 445 446class DoWhile(Node): 447 __slots__ = ('cond', 'stmt', 'coord', '__weakref__') 448 def __init__(self, cond, stmt, coord=None): 449 self.cond = cond 450 self.stmt = stmt 451 self.coord = coord 452 453 def children(self): 454 nodelist = [] 455 if self.cond is not None: nodelist.append(("cond", self.cond)) 456 if self.stmt is not None: nodelist.append(("stmt", self.stmt)) 457 return tuple(nodelist) 458 459 def __iter__(self): 460 if self.cond is not None: 461 yield self.cond 462 if self.stmt is not None: 463 yield self.stmt 464 465 attr_names = () 466 467class EllipsisParam(Node): 468 __slots__ = ('coord', '__weakref__') 469 def __init__(self, coord=None): 470 self.coord = coord 471 472 def children(self): 473 return () 474 475 def __iter__(self): 476 return 477 yield 478 479 attr_names = () 480 481class EmptyStatement(Node): 482 __slots__ = ('coord', '__weakref__') 483 def __init__(self, coord=None): 484 self.coord = coord 485 486 def children(self): 487 return () 488 489 def __iter__(self): 490 return 491 yield 492 493 attr_names = () 494 495class Enum(Node): 496 __slots__ = ('name', 'values', 'coord', '__weakref__') 497 def __init__(self, name, values, coord=None): 498 self.name = name 499 self.values = values 500 self.coord = coord 501 502 def children(self): 503 nodelist = [] 504 if self.values is not None: nodelist.append(("values", self.values)) 505 return tuple(nodelist) 506 507 def __iter__(self): 508 if self.values is not None: 509 yield self.values 510 511 attr_names = ('name', ) 512 513class Enumerator(Node): 514 __slots__ = ('name', 'value', 'coord', '__weakref__') 515 def __init__(self, name, value, coord=None): 516 self.name = name 517 self.value = value 518 self.coord = coord 519 520 def children(self): 521 nodelist = [] 522 if self.value is not None: nodelist.append(("value", self.value)) 523 return tuple(nodelist) 524 525 def __iter__(self): 526 if self.value is not None: 527 yield self.value 528 529 attr_names = ('name', ) 530 531class EnumeratorList(Node): 532 __slots__ = ('enumerators', 'coord', '__weakref__') 533 def __init__(self, enumerators, coord=None): 534 self.enumerators = enumerators 535 self.coord = coord 536 537 def children(self): 538 nodelist = [] 539 for i, child in enumerate(self.enumerators or []): 540 nodelist.append(("enumerators[%d]" % i, child)) 541 return tuple(nodelist) 542 543 def __iter__(self): 544 for child in (self.enumerators or []): 545 yield child 546 547 attr_names = () 548 549class ExprList(Node): 550 __slots__ = ('exprs', 'coord', '__weakref__') 551 def __init__(self, exprs, coord=None): 552 self.exprs = exprs 553 self.coord = coord 554 555 def children(self): 556 nodelist = [] 557 for i, child in enumerate(self.exprs or []): 558 nodelist.append(("exprs[%d]" % i, child)) 559 return tuple(nodelist) 560 561 def __iter__(self): 562 for child in (self.exprs or []): 563 yield child 564 565 attr_names = () 566 567class FileAST(Node): 568 __slots__ = ('ext', 'coord', '__weakref__') 569 def __init__(self, ext, coord=None): 570 self.ext = ext 571 self.coord = coord 572 573 def children(self): 574 nodelist = [] 575 for i, child in enumerate(self.ext or []): 576 nodelist.append(("ext[%d]" % i, child)) 577 return tuple(nodelist) 578 579 def __iter__(self): 580 for child in (self.ext or []): 581 yield child 582 583 attr_names = () 584 585class For(Node): 586 __slots__ = ('init', 'cond', 'next', 'stmt', 'coord', '__weakref__') 587 def __init__(self, init, cond, next, stmt, coord=None): 588 self.init = init 589 self.cond = cond 590 self.next = next 591 self.stmt = stmt 592 self.coord = coord 593 594 def children(self): 595 nodelist = [] 596 if self.init is not None: nodelist.append(("init", self.init)) 597 if self.cond is not None: nodelist.append(("cond", self.cond)) 598 if self.next is not None: nodelist.append(("next", self.next)) 599 if self.stmt is not None: nodelist.append(("stmt", self.stmt)) 600 return tuple(nodelist) 601 602 def __iter__(self): 603 if self.init is not None: 604 yield self.init 605 if self.cond is not None: 606 yield self.cond 607 if self.next is not None: 608 yield self.next 609 if self.stmt is not None: 610 yield self.stmt 611 612 attr_names = () 613 614class FuncCall(Node): 615 __slots__ = ('name', 'args', 'coord', '__weakref__') 616 def __init__(self, name, args, coord=None): 617 self.name = name 618 self.args = args 619 self.coord = coord 620 621 def children(self): 622 nodelist = [] 623 if self.name is not None: nodelist.append(("name", self.name)) 624 if self.args is not None: nodelist.append(("args", self.args)) 625 return tuple(nodelist) 626 627 def __iter__(self): 628 if self.name is not None: 629 yield self.name 630 if self.args is not None: 631 yield self.args 632 633 attr_names = () 634 635class FuncDecl(Node): 636 __slots__ = ('args', 'type', 'coord', '__weakref__') 637 def __init__(self, args, type, coord=None): 638 self.args = args 639 self.type = type 640 self.coord = coord 641 642 def children(self): 643 nodelist = [] 644 if self.args is not None: nodelist.append(("args", self.args)) 645 if self.type is not None: nodelist.append(("type", self.type)) 646 return tuple(nodelist) 647 648 def __iter__(self): 649 if self.args is not None: 650 yield self.args 651 if self.type is not None: 652 yield self.type 653 654 attr_names = () 655 656class FuncDef(Node): 657 __slots__ = ('decl', 'param_decls', 'body', 'coord', '__weakref__') 658 def __init__(self, decl, param_decls, body, coord=None): 659 self.decl = decl 660 self.param_decls = param_decls 661 self.body = body 662 self.coord = coord 663 664 def children(self): 665 nodelist = [] 666 if self.decl is not None: nodelist.append(("decl", self.decl)) 667 if self.body is not None: nodelist.append(("body", self.body)) 668 for i, child in enumerate(self.param_decls or []): 669 nodelist.append(("param_decls[%d]" % i, child)) 670 return tuple(nodelist) 671 672 def __iter__(self): 673 if self.decl is not None: 674 yield self.decl 675 if self.body is not None: 676 yield self.body 677 for child in (self.param_decls or []): 678 yield child 679 680 attr_names = () 681 682class Goto(Node): 683 __slots__ = ('name', 'coord', '__weakref__') 684 def __init__(self, name, coord=None): 685 self.name = name 686 self.coord = coord 687 688 def children(self): 689 nodelist = [] 690 return tuple(nodelist) 691 692 def __iter__(self): 693 return 694 yield 695 696 attr_names = ('name', ) 697 698class ID(Node): 699 __slots__ = ('name', 'coord', '__weakref__') 700 def __init__(self, name, coord=None): 701 self.name = name 702 self.coord = coord 703 704 def children(self): 705 nodelist = [] 706 return tuple(nodelist) 707 708 def __iter__(self): 709 return 710 yield 711 712 attr_names = ('name', ) 713 714class IdentifierType(Node): 715 __slots__ = ('names', 'coord', '__weakref__') 716 def __init__(self, names, coord=None): 717 self.names = names 718 self.coord = coord 719 720 def children(self): 721 nodelist = [] 722 return tuple(nodelist) 723 724 def __iter__(self): 725 return 726 yield 727 728 attr_names = ('names', ) 729 730class If(Node): 731 __slots__ = ('cond', 'iftrue', 'iffalse', 'coord', '__weakref__') 732 def __init__(self, cond, iftrue, iffalse, coord=None): 733 self.cond = cond 734 self.iftrue = iftrue 735 self.iffalse = iffalse 736 self.coord = coord 737 738 def children(self): 739 nodelist = [] 740 if self.cond is not None: nodelist.append(("cond", self.cond)) 741 if self.iftrue is not None: nodelist.append(("iftrue", self.iftrue)) 742 if self.iffalse is not None: nodelist.append(("iffalse", self.iffalse)) 743 return tuple(nodelist) 744 745 def __iter__(self): 746 if self.cond is not None: 747 yield self.cond 748 if self.iftrue is not None: 749 yield self.iftrue 750 if self.iffalse is not None: 751 yield self.iffalse 752 753 attr_names = () 754 755class InitList(Node): 756 __slots__ = ('exprs', 'coord', '__weakref__') 757 def __init__(self, exprs, coord=None): 758 self.exprs = exprs 759 self.coord = coord 760 761 def children(self): 762 nodelist = [] 763 for i, child in enumerate(self.exprs or []): 764 nodelist.append(("exprs[%d]" % i, child)) 765 return tuple(nodelist) 766 767 def __iter__(self): 768 for child in (self.exprs or []): 769 yield child 770 771 attr_names = () 772 773class Label(Node): 774 __slots__ = ('name', 'stmt', 'coord', '__weakref__') 775 def __init__(self, name, stmt, coord=None): 776 self.name = name 777 self.stmt = stmt 778 self.coord = coord 779 780 def children(self): 781 nodelist = [] 782 if self.stmt is not None: nodelist.append(("stmt", self.stmt)) 783 return tuple(nodelist) 784 785 def __iter__(self): 786 if self.stmt is not None: 787 yield self.stmt 788 789 attr_names = ('name', ) 790 791class NamedInitializer(Node): 792 __slots__ = ('name', 'expr', 'coord', '__weakref__') 793 def __init__(self, name, expr, coord=None): 794 self.name = name 795 self.expr = expr 796 self.coord = coord 797 798 def children(self): 799 nodelist = [] 800 if self.expr is not None: nodelist.append(("expr", self.expr)) 801 for i, child in enumerate(self.name or []): 802 nodelist.append(("name[%d]" % i, child)) 803 return tuple(nodelist) 804 805 def __iter__(self): 806 if self.expr is not None: 807 yield self.expr 808 for child in (self.name or []): 809 yield child 810 811 attr_names = () 812 813class ParamList(Node): 814 __slots__ = ('params', 'coord', '__weakref__') 815 def __init__(self, params, coord=None): 816 self.params = params 817 self.coord = coord 818 819 def children(self): 820 nodelist = [] 821 for i, child in enumerate(self.params or []): 822 nodelist.append(("params[%d]" % i, child)) 823 return tuple(nodelist) 824 825 def __iter__(self): 826 for child in (self.params or []): 827 yield child 828 829 attr_names = () 830 831class PtrDecl(Node): 832 __slots__ = ('quals', 'type', 'coord', '__weakref__') 833 def __init__(self, quals, type, coord=None): 834 self.quals = quals 835 self.type = type 836 self.coord = coord 837 838 def children(self): 839 nodelist = [] 840 if self.type is not None: nodelist.append(("type", self.type)) 841 return tuple(nodelist) 842 843 def __iter__(self): 844 if self.type is not None: 845 yield self.type 846 847 attr_names = ('quals', ) 848 849class Return(Node): 850 __slots__ = ('expr', 'coord', '__weakref__') 851 def __init__(self, expr, coord=None): 852 self.expr = expr 853 self.coord = coord 854 855 def children(self): 856 nodelist = [] 857 if self.expr is not None: nodelist.append(("expr", self.expr)) 858 return tuple(nodelist) 859 860 def __iter__(self): 861 if self.expr is not None: 862 yield self.expr 863 864 attr_names = () 865 866class Struct(Node): 867 __slots__ = ('name', 'decls', 'coord', '__weakref__') 868 def __init__(self, name, decls, coord=None): 869 self.name = name 870 self.decls = decls 871 self.coord = coord 872 873 def children(self): 874 nodelist = [] 875 for i, child in enumerate(self.decls or []): 876 nodelist.append(("decls[%d]" % i, child)) 877 return tuple(nodelist) 878 879 def __iter__(self): 880 for child in (self.decls or []): 881 yield child 882 883 attr_names = ('name', ) 884 885class StructRef(Node): 886 __slots__ = ('name', 'type', 'field', 'coord', '__weakref__') 887 def __init__(self, name, type, field, coord=None): 888 self.name = name 889 self.type = type 890 self.field = field 891 self.coord = coord 892 893 def children(self): 894 nodelist = [] 895 if self.name is not None: nodelist.append(("name", self.name)) 896 if self.field is not None: nodelist.append(("field", self.field)) 897 return tuple(nodelist) 898 899 def __iter__(self): 900 if self.name is not None: 901 yield self.name 902 if self.field is not None: 903 yield self.field 904 905 attr_names = ('type', ) 906 907class Switch(Node): 908 __slots__ = ('cond', 'stmt', 'coord', '__weakref__') 909 def __init__(self, cond, stmt, coord=None): 910 self.cond = cond 911 self.stmt = stmt 912 self.coord = coord 913 914 def children(self): 915 nodelist = [] 916 if self.cond is not None: nodelist.append(("cond", self.cond)) 917 if self.stmt is not None: nodelist.append(("stmt", self.stmt)) 918 return tuple(nodelist) 919 920 def __iter__(self): 921 if self.cond is not None: 922 yield self.cond 923 if self.stmt is not None: 924 yield self.stmt 925 926 attr_names = () 927 928class TernaryOp(Node): 929 __slots__ = ('cond', 'iftrue', 'iffalse', 'coord', '__weakref__') 930 def __init__(self, cond, iftrue, iffalse, coord=None): 931 self.cond = cond 932 self.iftrue = iftrue 933 self.iffalse = iffalse 934 self.coord = coord 935 936 def children(self): 937 nodelist = [] 938 if self.cond is not None: nodelist.append(("cond", self.cond)) 939 if self.iftrue is not None: nodelist.append(("iftrue", self.iftrue)) 940 if self.iffalse is not None: nodelist.append(("iffalse", self.iffalse)) 941 return tuple(nodelist) 942 943 def __iter__(self): 944 if self.cond is not None: 945 yield self.cond 946 if self.iftrue is not None: 947 yield self.iftrue 948 if self.iffalse is not None: 949 yield self.iffalse 950 951 attr_names = () 952 953class TypeDecl(Node): 954 __slots__ = ('declname', 'quals', 'type', 'coord', '__weakref__') 955 def __init__(self, declname, quals, type, coord=None): 956 self.declname = declname 957 self.quals = quals 958 self.type = type 959 self.coord = coord 960 961 def children(self): 962 nodelist = [] 963 if self.type is not None: nodelist.append(("type", self.type)) 964 return tuple(nodelist) 965 966 def __iter__(self): 967 if self.type is not None: 968 yield self.type 969 970 attr_names = ('declname', 'quals', ) 971 972class Typedef(Node): 973 __slots__ = ('name', 'quals', 'storage', 'type', 'coord', '__weakref__') 974 def __init__(self, name, quals, storage, type, coord=None): 975 self.name = name 976 self.quals = quals 977 self.storage = storage 978 self.type = type 979 self.coord = coord 980 981 def children(self): 982 nodelist = [] 983 if self.type is not None: nodelist.append(("type", self.type)) 984 return tuple(nodelist) 985 986 def __iter__(self): 987 if self.type is not None: 988 yield self.type 989 990 attr_names = ('name', 'quals', 'storage', ) 991 992class Typename(Node): 993 __slots__ = ('name', 'quals', 'type', 'coord', '__weakref__') 994 def __init__(self, name, quals, type, coord=None): 995 self.name = name 996 self.quals = quals 997 self.type = type 998 self.coord = coord 999 1000 def children(self): 1001 nodelist = [] 1002 if self.type is not None: nodelist.append(("type", self.type)) 1003 return tuple(nodelist) 1004 1005 def __iter__(self): 1006 if self.type is not None: 1007 yield self.type 1008 1009 attr_names = ('name', 'quals', ) 1010 1011class UnaryOp(Node): 1012 __slots__ = ('op', 'expr', 'coord', '__weakref__') 1013 def __init__(self, op, expr, coord=None): 1014 self.op = op 1015 self.expr = expr 1016 self.coord = coord 1017 1018 def children(self): 1019 nodelist = [] 1020 if self.expr is not None: nodelist.append(("expr", self.expr)) 1021 return tuple(nodelist) 1022 1023 def __iter__(self): 1024 if self.expr is not None: 1025 yield self.expr 1026 1027 attr_names = ('op', ) 1028 1029class Union(Node): 1030 __slots__ = ('name', 'decls', 'coord', '__weakref__') 1031 def __init__(self, name, decls, coord=None): 1032 self.name = name 1033 self.decls = decls 1034 self.coord = coord 1035 1036 def children(self): 1037 nodelist = [] 1038 for i, child in enumerate(self.decls or []): 1039 nodelist.append(("decls[%d]" % i, child)) 1040 return tuple(nodelist) 1041 1042 def __iter__(self): 1043 for child in (self.decls or []): 1044 yield child 1045 1046 attr_names = ('name', ) 1047 1048class While(Node): 1049 __slots__ = ('cond', 'stmt', 'coord', '__weakref__') 1050 def __init__(self, cond, stmt, coord=None): 1051 self.cond = cond 1052 self.stmt = stmt 1053 self.coord = coord 1054 1055 def children(self): 1056 nodelist = [] 1057 if self.cond is not None: nodelist.append(("cond", self.cond)) 1058 if self.stmt is not None: nodelist.append(("stmt", self.stmt)) 1059 return tuple(nodelist) 1060 1061 def __iter__(self): 1062 if self.cond is not None: 1063 yield self.cond 1064 if self.stmt is not None: 1065 yield self.stmt 1066 1067 attr_names = () 1068 1069class Pragma(Node): 1070 __slots__ = ('string', 'coord', '__weakref__') 1071 def __init__(self, string, coord=None): 1072 self.string = string 1073 self.coord = coord 1074 1075 def children(self): 1076 nodelist = [] 1077 return tuple(nodelist) 1078 1079 def __iter__(self): 1080 return 1081 yield 1082 1083 attr_names = ('string', ) 1084 1085