Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pycparser/c_ast.py: 1%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -----------------------------------------------------------------
2# ** ATTENTION **
3# This code was automatically generated from _c_ast.cfg
4#
5# Do not modify it directly. Modify the configuration file and
6# run the generator again.
7# ** ** *** ** **
8#
9# pycparser: c_ast.py
10#
11# AST Node classes.
12#
13# Eli Bendersky [https://eli.thegreenplace.net/]
14# License: BSD
15# -----------------------------------------------------------------
18import sys
19from typing import Any, ClassVar, IO, Optional
22def _repr(obj):
23 """
24 Get the representation of an object, with dedicated pprint-like format for lists.
25 """
26 if isinstance(obj, list):
27 return "[" + (",\n ".join((_repr(e).replace("\n", "\n ") for e in obj))) + "\n]"
28 else:
29 return repr(obj)
32class Node:
33 __slots__ = ()
34 """ Abstract base class for AST nodes.
35 """
36 attr_names: ClassVar[tuple[str, ...]] = ()
37 coord: Optional[Any]
39 def __repr__(self):
40 """Generates a python representation of the current node"""
41 result = self.__class__.__name__ + "("
43 indent = ""
44 separator = ""
45 for name in self.__slots__[:-2]:
46 result += separator
47 result += indent
48 result += (
49 name
50 + "="
51 + (
52 _repr(getattr(self, name)).replace(
53 "\n",
54 "\n " + (" " * (len(name) + len(self.__class__.__name__))),
55 )
56 )
57 )
59 separator = ","
60 indent = "\n " + (" " * len(self.__class__.__name__))
62 result += indent + ")"
64 return result
66 def children(self):
67 """A sequence of all children that are Nodes"""
68 pass
70 def show(
71 self,
72 buf: IO[str] = sys.stdout,
73 offset: int = 0,
74 attrnames: bool = False,
75 showemptyattrs: bool = True,
76 nodenames: bool = False,
77 showcoord: bool = False,
78 _my_node_name: Optional[str] = None,
79 ):
80 """Pretty print the Node and all its attributes and
81 children (recursively) to a buffer.
83 buf:
84 Open IO buffer into which the Node is printed.
86 offset:
87 Initial offset (amount of leading spaces)
89 attrnames:
90 True if you want to see the attribute names in
91 name=value pairs. False to only see the values.
93 showemptyattrs:
94 False if you want to suppress printing empty attributes.
96 nodenames:
97 True if you want to see the actual node names
98 within their parents.
100 showcoord:
101 Do you want the coordinates of each Node to be
102 displayed.
103 """
104 lead = " " * offset
105 if nodenames and _my_node_name is not None:
106 buf.write(lead + self.__class__.__name__ + " <" + _my_node_name + ">: ")
107 else:
108 buf.write(lead + self.__class__.__name__ + ": ")
110 if self.attr_names:
112 def is_empty(v):
113 v is None or (hasattr(v, "__len__") and len(v) == 0)
115 nvlist = [
116 (n, getattr(self, n))
117 for n in self.attr_names
118 if showemptyattrs or not is_empty(getattr(self, n))
119 ]
120 if attrnames:
121 attrstr = ", ".join(f"{name}={value}" for name, value in nvlist)
122 else:
123 attrstr = ", ".join(f"{value}" for _, value in nvlist)
124 buf.write(attrstr)
126 if showcoord:
127 buf.write(f" (at {self.coord})")
128 buf.write("\n")
130 for child_name, child in self.children():
131 child.show(
132 buf,
133 offset=offset + 2,
134 attrnames=attrnames,
135 showemptyattrs=showemptyattrs,
136 nodenames=nodenames,
137 showcoord=showcoord,
138 _my_node_name=child_name,
139 )
142class NodeVisitor:
143 """A base NodeVisitor class for visiting c_ast nodes.
144 Subclass it and define your own visit_XXX methods, where
145 XXX is the class name you want to visit with these
146 methods.
148 For example:
150 class ConstantVisitor(NodeVisitor):
151 def __init__(self):
152 self.values = []
154 def visit_Constant(self, node):
155 self.values.append(node.value)
157 Creates a list of values of all the constant nodes
158 encountered below the given node. To use it:
160 cv = ConstantVisitor()
161 cv.visit(node)
163 Notes:
165 * generic_visit() will be called for AST nodes for which
166 no visit_XXX method was defined.
167 * The children of nodes for which a visit_XXX was
168 defined will not be visited - if you need this, call
169 generic_visit() on the node.
170 You can use:
171 NodeVisitor.generic_visit(self, node)
172 * Modeled after Python's own AST visiting facilities
173 (the ast module of Python 3.0)
174 """
176 _method_cache = None
178 def visit(self, node: Node):
179 """Visit a node."""
181 if self._method_cache is None:
182 self._method_cache = {}
184 visitor = self._method_cache.get(node.__class__.__name__, None)
185 if visitor is None:
186 method = "visit_" + node.__class__.__name__
187 visitor = getattr(self, method, self.generic_visit)
188 self._method_cache[node.__class__.__name__] = visitor
190 return visitor(node)
192 def generic_visit(self, node: Node):
193 """Called if no explicit visitor function exists for a
194 node. Implements preorder visiting of the node.
195 """
196 for _, c in node.children():
197 self.visit(c)
200class ArrayDecl(Node):
201 __slots__ = ("type", "dim", "dim_quals", "coord", "__weakref__")
203 def __init__(self, type, dim, dim_quals, coord=None):
204 self.type = type
205 self.dim = dim
206 self.dim_quals = dim_quals
207 self.coord = coord
209 def children(self):
210 nodelist = []
211 if self.type is not None:
212 nodelist.append(("type", self.type))
213 if self.dim is not None:
214 nodelist.append(("dim", self.dim))
215 return tuple(nodelist)
217 def __iter__(self):
218 if self.type is not None:
219 yield self.type
220 if self.dim is not None:
221 yield self.dim
223 attr_names = ("dim_quals",)
226class ArrayRef(Node):
227 __slots__ = ("name", "subscript", "coord", "__weakref__")
229 def __init__(self, name, subscript, coord=None):
230 self.name = name
231 self.subscript = subscript
232 self.coord = coord
234 def children(self):
235 nodelist = []
236 if self.name is not None:
237 nodelist.append(("name", self.name))
238 if self.subscript is not None:
239 nodelist.append(("subscript", self.subscript))
240 return tuple(nodelist)
242 def __iter__(self):
243 if self.name is not None:
244 yield self.name
245 if self.subscript is not None:
246 yield self.subscript
248 attr_names = ()
251class Assignment(Node):
252 __slots__ = ("op", "lvalue", "rvalue", "coord", "__weakref__")
254 def __init__(self, op, lvalue, rvalue, coord=None):
255 self.op = op
256 self.lvalue = lvalue
257 self.rvalue = rvalue
258 self.coord = coord
260 def children(self):
261 nodelist = []
262 if self.lvalue is not None:
263 nodelist.append(("lvalue", self.lvalue))
264 if self.rvalue is not None:
265 nodelist.append(("rvalue", self.rvalue))
266 return tuple(nodelist)
268 def __iter__(self):
269 if self.lvalue is not None:
270 yield self.lvalue
271 if self.rvalue is not None:
272 yield self.rvalue
274 attr_names = ("op",)
277class Alignas(Node):
278 __slots__ = ("alignment", "coord", "__weakref__")
280 def __init__(self, alignment, coord=None):
281 self.alignment = alignment
282 self.coord = coord
284 def children(self):
285 nodelist = []
286 if self.alignment is not None:
287 nodelist.append(("alignment", self.alignment))
288 return tuple(nodelist)
290 def __iter__(self):
291 if self.alignment is not None:
292 yield self.alignment
294 attr_names = ()
297class BinaryOp(Node):
298 __slots__ = ("op", "left", "right", "coord", "__weakref__")
300 def __init__(self, op, left, right, coord=None):
301 self.op = op
302 self.left = left
303 self.right = right
304 self.coord = coord
306 def children(self):
307 nodelist = []
308 if self.left is not None:
309 nodelist.append(("left", self.left))
310 if self.right is not None:
311 nodelist.append(("right", self.right))
312 return tuple(nodelist)
314 def __iter__(self):
315 if self.left is not None:
316 yield self.left
317 if self.right is not None:
318 yield self.right
320 attr_names = ("op",)
323class Break(Node):
324 __slots__ = ("coord", "__weakref__")
326 def __init__(self, coord=None):
327 self.coord = coord
329 def children(self):
330 return ()
332 def __iter__(self):
333 return
334 yield
336 attr_names = ()
339class Case(Node):
340 __slots__ = ("expr", "stmts", "coord", "__weakref__")
342 def __init__(self, expr, stmts, coord=None):
343 self.expr = expr
344 self.stmts = stmts
345 self.coord = coord
347 def children(self):
348 nodelist = []
349 if self.expr is not None:
350 nodelist.append(("expr", self.expr))
351 for i, child in enumerate(self.stmts or []):
352 nodelist.append((f"stmts[{i}]", child))
353 return tuple(nodelist)
355 def __iter__(self):
356 if self.expr is not None:
357 yield self.expr
358 for child in self.stmts or []:
359 yield child
361 attr_names = ()
364class Cast(Node):
365 __slots__ = ("to_type", "expr", "coord", "__weakref__")
367 def __init__(self, to_type, expr, coord=None):
368 self.to_type = to_type
369 self.expr = expr
370 self.coord = coord
372 def children(self):
373 nodelist = []
374 if self.to_type is not None:
375 nodelist.append(("to_type", self.to_type))
376 if self.expr is not None:
377 nodelist.append(("expr", self.expr))
378 return tuple(nodelist)
380 def __iter__(self):
381 if self.to_type is not None:
382 yield self.to_type
383 if self.expr is not None:
384 yield self.expr
386 attr_names = ()
389class Compound(Node):
390 __slots__ = ("block_items", "coord", "__weakref__")
392 def __init__(self, block_items, coord=None):
393 self.block_items = block_items
394 self.coord = coord
396 def children(self):
397 nodelist = []
398 for i, child in enumerate(self.block_items or []):
399 nodelist.append((f"block_items[{i}]", child))
400 return tuple(nodelist)
402 def __iter__(self):
403 for child in self.block_items or []:
404 yield child
406 attr_names = ()
409class CompoundLiteral(Node):
410 __slots__ = ("type", "init", "coord", "__weakref__")
412 def __init__(self, type, init, coord=None):
413 self.type = type
414 self.init = init
415 self.coord = coord
417 def children(self):
418 nodelist = []
419 if self.type is not None:
420 nodelist.append(("type", self.type))
421 if self.init is not None:
422 nodelist.append(("init", self.init))
423 return tuple(nodelist)
425 def __iter__(self):
426 if self.type is not None:
427 yield self.type
428 if self.init is not None:
429 yield self.init
431 attr_names = ()
434class Constant(Node):
435 __slots__ = ("type", "value", "coord", "__weakref__")
437 def __init__(self, type, value, coord=None):
438 self.type = type
439 self.value = value
440 self.coord = coord
442 def children(self):
443 nodelist = []
444 return tuple(nodelist)
446 def __iter__(self):
447 return
448 yield
450 attr_names = (
451 "type",
452 "value",
453 )
456class Continue(Node):
457 __slots__ = ("coord", "__weakref__")
459 def __init__(self, coord=None):
460 self.coord = coord
462 def children(self):
463 return ()
465 def __iter__(self):
466 return
467 yield
469 attr_names = ()
472class Decl(Node):
473 __slots__ = (
474 "name",
475 "quals",
476 "align",
477 "storage",
478 "funcspec",
479 "type",
480 "init",
481 "bitsize",
482 "coord",
483 "__weakref__",
484 )
486 def __init__(
487 self, name, quals, align, storage, funcspec, type, init, bitsize, coord=None
488 ):
489 self.name = name
490 self.quals = quals
491 self.align = align
492 self.storage = storage
493 self.funcspec = funcspec
494 self.type = type
495 self.init = init
496 self.bitsize = bitsize
497 self.coord = coord
499 def children(self):
500 nodelist = []
501 if self.type is not None:
502 nodelist.append(("type", self.type))
503 if self.init is not None:
504 nodelist.append(("init", self.init))
505 if self.bitsize is not None:
506 nodelist.append(("bitsize", self.bitsize))
507 return tuple(nodelist)
509 def __iter__(self):
510 if self.type is not None:
511 yield self.type
512 if self.init is not None:
513 yield self.init
514 if self.bitsize is not None:
515 yield self.bitsize
517 attr_names = (
518 "name",
519 "quals",
520 "align",
521 "storage",
522 "funcspec",
523 )
526class DeclList(Node):
527 __slots__ = ("decls", "coord", "__weakref__")
529 def __init__(self, decls, coord=None):
530 self.decls = decls
531 self.coord = coord
533 def children(self):
534 nodelist = []
535 for i, child in enumerate(self.decls or []):
536 nodelist.append((f"decls[{i}]", child))
537 return tuple(nodelist)
539 def __iter__(self):
540 for child in self.decls or []:
541 yield child
543 attr_names = ()
546class Default(Node):
547 __slots__ = ("stmts", "coord", "__weakref__")
549 def __init__(self, stmts, coord=None):
550 self.stmts = stmts
551 self.coord = coord
553 def children(self):
554 nodelist = []
555 for i, child in enumerate(self.stmts or []):
556 nodelist.append((f"stmts[{i}]", child))
557 return tuple(nodelist)
559 def __iter__(self):
560 for child in self.stmts or []:
561 yield child
563 attr_names = ()
566class DoWhile(Node):
567 __slots__ = ("cond", "stmt", "coord", "__weakref__")
569 def __init__(self, cond, stmt, coord=None):
570 self.cond = cond
571 self.stmt = stmt
572 self.coord = coord
574 def children(self):
575 nodelist = []
576 if self.cond is not None:
577 nodelist.append(("cond", self.cond))
578 if self.stmt is not None:
579 nodelist.append(("stmt", self.stmt))
580 return tuple(nodelist)
582 def __iter__(self):
583 if self.cond is not None:
584 yield self.cond
585 if self.stmt is not None:
586 yield self.stmt
588 attr_names = ()
591class EllipsisParam(Node):
592 __slots__ = ("coord", "__weakref__")
594 def __init__(self, coord=None):
595 self.coord = coord
597 def children(self):
598 return ()
600 def __iter__(self):
601 return
602 yield
604 attr_names = ()
607class EmptyStatement(Node):
608 __slots__ = ("coord", "__weakref__")
610 def __init__(self, coord=None):
611 self.coord = coord
613 def children(self):
614 return ()
616 def __iter__(self):
617 return
618 yield
620 attr_names = ()
623class Enum(Node):
624 __slots__ = ("name", "values", "coord", "__weakref__")
626 def __init__(self, name, values, coord=None):
627 self.name = name
628 self.values = values
629 self.coord = coord
631 def children(self):
632 nodelist = []
633 if self.values is not None:
634 nodelist.append(("values", self.values))
635 return tuple(nodelist)
637 def __iter__(self):
638 if self.values is not None:
639 yield self.values
641 attr_names = ("name",)
644class Enumerator(Node):
645 __slots__ = ("name", "value", "coord", "__weakref__")
647 def __init__(self, name, value, coord=None):
648 self.name = name
649 self.value = value
650 self.coord = coord
652 def children(self):
653 nodelist = []
654 if self.value is not None:
655 nodelist.append(("value", self.value))
656 return tuple(nodelist)
658 def __iter__(self):
659 if self.value is not None:
660 yield self.value
662 attr_names = ("name",)
665class EnumeratorList(Node):
666 __slots__ = ("enumerators", "coord", "__weakref__")
668 def __init__(self, enumerators, coord=None):
669 self.enumerators = enumerators
670 self.coord = coord
672 def children(self):
673 nodelist = []
674 for i, child in enumerate(self.enumerators or []):
675 nodelist.append((f"enumerators[{i}]", child))
676 return tuple(nodelist)
678 def __iter__(self):
679 for child in self.enumerators or []:
680 yield child
682 attr_names = ()
685class ExprList(Node):
686 __slots__ = ("exprs", "coord", "__weakref__")
688 def __init__(self, exprs, coord=None):
689 self.exprs = exprs
690 self.coord = coord
692 def children(self):
693 nodelist = []
694 for i, child in enumerate(self.exprs or []):
695 nodelist.append((f"exprs[{i}]", child))
696 return tuple(nodelist)
698 def __iter__(self):
699 for child in self.exprs or []:
700 yield child
702 attr_names = ()
705class FileAST(Node):
706 __slots__ = ("ext", "coord", "__weakref__")
708 def __init__(self, ext, coord=None):
709 self.ext = ext
710 self.coord = coord
712 def children(self):
713 nodelist = []
714 for i, child in enumerate(self.ext or []):
715 nodelist.append((f"ext[{i}]", child))
716 return tuple(nodelist)
718 def __iter__(self):
719 for child in self.ext or []:
720 yield child
722 attr_names = ()
725class For(Node):
726 __slots__ = ("init", "cond", "next", "stmt", "coord", "__weakref__")
728 def __init__(self, init, cond, next, stmt, coord=None):
729 self.init = init
730 self.cond = cond
731 self.next = next
732 self.stmt = stmt
733 self.coord = coord
735 def children(self):
736 nodelist = []
737 if self.init is not None:
738 nodelist.append(("init", self.init))
739 if self.cond is not None:
740 nodelist.append(("cond", self.cond))
741 if self.next is not None:
742 nodelist.append(("next", self.next))
743 if self.stmt is not None:
744 nodelist.append(("stmt", self.stmt))
745 return tuple(nodelist)
747 def __iter__(self):
748 if self.init is not None:
749 yield self.init
750 if self.cond is not None:
751 yield self.cond
752 if self.next is not None:
753 yield self.next
754 if self.stmt is not None:
755 yield self.stmt
757 attr_names = ()
760class FuncCall(Node):
761 __slots__ = ("name", "args", "coord", "__weakref__")
763 def __init__(self, name, args, coord=None):
764 self.name = name
765 self.args = args
766 self.coord = coord
768 def children(self):
769 nodelist = []
770 if self.name is not None:
771 nodelist.append(("name", self.name))
772 if self.args is not None:
773 nodelist.append(("args", self.args))
774 return tuple(nodelist)
776 def __iter__(self):
777 if self.name is not None:
778 yield self.name
779 if self.args is not None:
780 yield self.args
782 attr_names = ()
785class FuncDecl(Node):
786 __slots__ = ("args", "type", "coord", "__weakref__")
788 def __init__(self, args, type, coord=None):
789 self.args = args
790 self.type = type
791 self.coord = coord
793 def children(self):
794 nodelist = []
795 if self.args is not None:
796 nodelist.append(("args", self.args))
797 if self.type is not None:
798 nodelist.append(("type", self.type))
799 return tuple(nodelist)
801 def __iter__(self):
802 if self.args is not None:
803 yield self.args
804 if self.type is not None:
805 yield self.type
807 attr_names = ()
810class FuncDef(Node):
811 __slots__ = ("decl", "param_decls", "body", "coord", "__weakref__")
813 def __init__(self, decl, param_decls, body, coord=None):
814 self.decl = decl
815 self.param_decls = param_decls
816 self.body = body
817 self.coord = coord
819 def children(self):
820 nodelist = []
821 if self.decl is not None:
822 nodelist.append(("decl", self.decl))
823 if self.body is not None:
824 nodelist.append(("body", self.body))
825 for i, child in enumerate(self.param_decls or []):
826 nodelist.append((f"param_decls[{i}]", child))
827 return tuple(nodelist)
829 def __iter__(self):
830 if self.decl is not None:
831 yield self.decl
832 if self.body is not None:
833 yield self.body
834 for child in self.param_decls or []:
835 yield child
837 attr_names = ()
840class Goto(Node):
841 __slots__ = ("name", "coord", "__weakref__")
843 def __init__(self, name, coord=None):
844 self.name = name
845 self.coord = coord
847 def children(self):
848 nodelist = []
849 return tuple(nodelist)
851 def __iter__(self):
852 return
853 yield
855 attr_names = ("name",)
858class ID(Node):
859 __slots__ = ("name", "coord", "__weakref__")
861 def __init__(self, name, coord=None):
862 self.name = name
863 self.coord = coord
865 def children(self):
866 nodelist = []
867 return tuple(nodelist)
869 def __iter__(self):
870 return
871 yield
873 attr_names = ("name",)
876class IdentifierType(Node):
877 __slots__ = ("names", "coord", "__weakref__")
879 def __init__(self, names, coord=None):
880 self.names = names
881 self.coord = coord
883 def children(self):
884 nodelist = []
885 return tuple(nodelist)
887 def __iter__(self):
888 return
889 yield
891 attr_names = ("names",)
894class If(Node):
895 __slots__ = ("cond", "iftrue", "iffalse", "coord", "__weakref__")
897 def __init__(self, cond, iftrue, iffalse, coord=None):
898 self.cond = cond
899 self.iftrue = iftrue
900 self.iffalse = iffalse
901 self.coord = coord
903 def children(self):
904 nodelist = []
905 if self.cond is not None:
906 nodelist.append(("cond", self.cond))
907 if self.iftrue is not None:
908 nodelist.append(("iftrue", self.iftrue))
909 if self.iffalse is not None:
910 nodelist.append(("iffalse", self.iffalse))
911 return tuple(nodelist)
913 def __iter__(self):
914 if self.cond is not None:
915 yield self.cond
916 if self.iftrue is not None:
917 yield self.iftrue
918 if self.iffalse is not None:
919 yield self.iffalse
921 attr_names = ()
924class InitList(Node):
925 __slots__ = ("exprs", "coord", "__weakref__")
927 def __init__(self, exprs, coord=None):
928 self.exprs = exprs
929 self.coord = coord
931 def children(self):
932 nodelist = []
933 for i, child in enumerate(self.exprs or []):
934 nodelist.append((f"exprs[{i}]", child))
935 return tuple(nodelist)
937 def __iter__(self):
938 for child in self.exprs or []:
939 yield child
941 attr_names = ()
944class Label(Node):
945 __slots__ = ("name", "stmt", "coord", "__weakref__")
947 def __init__(self, name, stmt, coord=None):
948 self.name = name
949 self.stmt = stmt
950 self.coord = coord
952 def children(self):
953 nodelist = []
954 if self.stmt is not None:
955 nodelist.append(("stmt", self.stmt))
956 return tuple(nodelist)
958 def __iter__(self):
959 if self.stmt is not None:
960 yield self.stmt
962 attr_names = ("name",)
965class NamedInitializer(Node):
966 __slots__ = ("name", "expr", "coord", "__weakref__")
968 def __init__(self, name, expr, coord=None):
969 self.name = name
970 self.expr = expr
971 self.coord = coord
973 def children(self):
974 nodelist = []
975 if self.expr is not None:
976 nodelist.append(("expr", self.expr))
977 for i, child in enumerate(self.name or []):
978 nodelist.append((f"name[{i}]", child))
979 return tuple(nodelist)
981 def __iter__(self):
982 if self.expr is not None:
983 yield self.expr
984 for child in self.name or []:
985 yield child
987 attr_names = ()
990class ParamList(Node):
991 __slots__ = ("params", "coord", "__weakref__")
993 def __init__(self, params, coord=None):
994 self.params = params
995 self.coord = coord
997 def children(self):
998 nodelist = []
999 for i, child in enumerate(self.params or []):
1000 nodelist.append((f"params[{i}]", child))
1001 return tuple(nodelist)
1003 def __iter__(self):
1004 for child in self.params or []:
1005 yield child
1007 attr_names = ()
1010class PtrDecl(Node):
1011 __slots__ = ("quals", "type", "coord", "__weakref__")
1013 def __init__(self, quals, type, coord=None):
1014 self.quals = quals
1015 self.type = type
1016 self.coord = coord
1018 def children(self):
1019 nodelist = []
1020 if self.type is not None:
1021 nodelist.append(("type", self.type))
1022 return tuple(nodelist)
1024 def __iter__(self):
1025 if self.type is not None:
1026 yield self.type
1028 attr_names = ("quals",)
1031class Return(Node):
1032 __slots__ = ("expr", "coord", "__weakref__")
1034 def __init__(self, expr, coord=None):
1035 self.expr = expr
1036 self.coord = coord
1038 def children(self):
1039 nodelist = []
1040 if self.expr is not None:
1041 nodelist.append(("expr", self.expr))
1042 return tuple(nodelist)
1044 def __iter__(self):
1045 if self.expr is not None:
1046 yield self.expr
1048 attr_names = ()
1051class StaticAssert(Node):
1052 __slots__ = ("cond", "message", "coord", "__weakref__")
1054 def __init__(self, cond, message, coord=None):
1055 self.cond = cond
1056 self.message = message
1057 self.coord = coord
1059 def children(self):
1060 nodelist = []
1061 if self.cond is not None:
1062 nodelist.append(("cond", self.cond))
1063 if self.message is not None:
1064 nodelist.append(("message", self.message))
1065 return tuple(nodelist)
1067 def __iter__(self):
1068 if self.cond is not None:
1069 yield self.cond
1070 if self.message is not None:
1071 yield self.message
1073 attr_names = ()
1076class Struct(Node):
1077 __slots__ = ("name", "decls", "coord", "__weakref__")
1079 def __init__(self, name, decls, coord=None):
1080 self.name = name
1081 self.decls = decls
1082 self.coord = coord
1084 def children(self):
1085 nodelist = []
1086 for i, child in enumerate(self.decls or []):
1087 nodelist.append((f"decls[{i}]", child))
1088 return tuple(nodelist)
1090 def __iter__(self):
1091 for child in self.decls or []:
1092 yield child
1094 attr_names = ("name",)
1097class StructRef(Node):
1098 __slots__ = ("name", "type", "field", "coord", "__weakref__")
1100 def __init__(self, name, type, field, coord=None):
1101 self.name = name
1102 self.type = type
1103 self.field = field
1104 self.coord = coord
1106 def children(self):
1107 nodelist = []
1108 if self.name is not None:
1109 nodelist.append(("name", self.name))
1110 if self.field is not None:
1111 nodelist.append(("field", self.field))
1112 return tuple(nodelist)
1114 def __iter__(self):
1115 if self.name is not None:
1116 yield self.name
1117 if self.field is not None:
1118 yield self.field
1120 attr_names = ("type",)
1123class Switch(Node):
1124 __slots__ = ("cond", "stmt", "coord", "__weakref__")
1126 def __init__(self, cond, stmt, coord=None):
1127 self.cond = cond
1128 self.stmt = stmt
1129 self.coord = coord
1131 def children(self):
1132 nodelist = []
1133 if self.cond is not None:
1134 nodelist.append(("cond", self.cond))
1135 if self.stmt is not None:
1136 nodelist.append(("stmt", self.stmt))
1137 return tuple(nodelist)
1139 def __iter__(self):
1140 if self.cond is not None:
1141 yield self.cond
1142 if self.stmt is not None:
1143 yield self.stmt
1145 attr_names = ()
1148class TernaryOp(Node):
1149 __slots__ = ("cond", "iftrue", "iffalse", "coord", "__weakref__")
1151 def __init__(self, cond, iftrue, iffalse, coord=None):
1152 self.cond = cond
1153 self.iftrue = iftrue
1154 self.iffalse = iffalse
1155 self.coord = coord
1157 def children(self):
1158 nodelist = []
1159 if self.cond is not None:
1160 nodelist.append(("cond", self.cond))
1161 if self.iftrue is not None:
1162 nodelist.append(("iftrue", self.iftrue))
1163 if self.iffalse is not None:
1164 nodelist.append(("iffalse", self.iffalse))
1165 return tuple(nodelist)
1167 def __iter__(self):
1168 if self.cond is not None:
1169 yield self.cond
1170 if self.iftrue is not None:
1171 yield self.iftrue
1172 if self.iffalse is not None:
1173 yield self.iffalse
1175 attr_names = ()
1178class TypeDecl(Node):
1179 __slots__ = ("declname", "quals", "align", "type", "coord", "__weakref__")
1181 def __init__(self, declname, quals, align, type, coord=None):
1182 self.declname = declname
1183 self.quals = quals
1184 self.align = align
1185 self.type = type
1186 self.coord = coord
1188 def children(self):
1189 nodelist = []
1190 if self.type is not None:
1191 nodelist.append(("type", self.type))
1192 return tuple(nodelist)
1194 def __iter__(self):
1195 if self.type is not None:
1196 yield self.type
1198 attr_names = (
1199 "declname",
1200 "quals",
1201 "align",
1202 )
1205class Typedef(Node):
1206 __slots__ = ("name", "quals", "storage", "type", "coord", "__weakref__")
1208 def __init__(self, name, quals, storage, type, coord=None):
1209 self.name = name
1210 self.quals = quals
1211 self.storage = storage
1212 self.type = type
1213 self.coord = coord
1215 def children(self):
1216 nodelist = []
1217 if self.type is not None:
1218 nodelist.append(("type", self.type))
1219 return tuple(nodelist)
1221 def __iter__(self):
1222 if self.type is not None:
1223 yield self.type
1225 attr_names = (
1226 "name",
1227 "quals",
1228 "storage",
1229 )
1232class Typename(Node):
1233 __slots__ = ("name", "quals", "align", "type", "coord", "__weakref__")
1235 def __init__(self, name, quals, align, type, coord=None):
1236 self.name = name
1237 self.quals = quals
1238 self.align = align
1239 self.type = type
1240 self.coord = coord
1242 def children(self):
1243 nodelist = []
1244 if self.type is not None:
1245 nodelist.append(("type", self.type))
1246 return tuple(nodelist)
1248 def __iter__(self):
1249 if self.type is not None:
1250 yield self.type
1252 attr_names = (
1253 "name",
1254 "quals",
1255 "align",
1256 )
1259class UnaryOp(Node):
1260 __slots__ = ("op", "expr", "coord", "__weakref__")
1262 def __init__(self, op, expr, coord=None):
1263 self.op = op
1264 self.expr = expr
1265 self.coord = coord
1267 def children(self):
1268 nodelist = []
1269 if self.expr is not None:
1270 nodelist.append(("expr", self.expr))
1271 return tuple(nodelist)
1273 def __iter__(self):
1274 if self.expr is not None:
1275 yield self.expr
1277 attr_names = ("op",)
1280class Union(Node):
1281 __slots__ = ("name", "decls", "coord", "__weakref__")
1283 def __init__(self, name, decls, coord=None):
1284 self.name = name
1285 self.decls = decls
1286 self.coord = coord
1288 def children(self):
1289 nodelist = []
1290 for i, child in enumerate(self.decls or []):
1291 nodelist.append((f"decls[{i}]", child))
1292 return tuple(nodelist)
1294 def __iter__(self):
1295 for child in self.decls or []:
1296 yield child
1298 attr_names = ("name",)
1301class While(Node):
1302 __slots__ = ("cond", "stmt", "coord", "__weakref__")
1304 def __init__(self, cond, stmt, coord=None):
1305 self.cond = cond
1306 self.stmt = stmt
1307 self.coord = coord
1309 def children(self):
1310 nodelist = []
1311 if self.cond is not None:
1312 nodelist.append(("cond", self.cond))
1313 if self.stmt is not None:
1314 nodelist.append(("stmt", self.stmt))
1315 return tuple(nodelist)
1317 def __iter__(self):
1318 if self.cond is not None:
1319 yield self.cond
1320 if self.stmt is not None:
1321 yield self.stmt
1323 attr_names = ()
1326class Pragma(Node):
1327 __slots__ = ("string", "coord", "__weakref__")
1329 def __init__(self, string, coord=None):
1330 self.string = string
1331 self.coord = coord
1333 def children(self):
1334 nodelist = []
1335 return tuple(nodelist)
1337 def __iter__(self):
1338 return
1339 yield
1341 attr_names = ("string",)