Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pycparser/c_ast.py: 49%
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 'make regen-ast' from the repository root to regenerate and format it.
7# ** ** *** ** **
8#
9# The order of generated __slots__ is significant to Node.__repr__.
10# ruff: noqa: RUF023
11#
12# pycparser: c_ast.py
13#
14# AST Node classes.
15#
16# Eli Bendersky [https://eli.thegreenplace.net/]
17# License: BSD
18# -----------------------------------------------------------------
21import sys
22from typing import IO, Any, ClassVar
25def _repr(obj):
26 """
27 Get the representation of an object, with dedicated pprint-like format for lists.
28 """
29 if isinstance(obj, list):
30 return "[" + (",\n ".join(_repr(e).replace("\n", "\n ") for e in obj)) + "\n]"
31 else:
32 return repr(obj)
35class Node:
36 __slots__ = ()
37 """ Abstract base class for AST nodes.
38 """
39 attr_names: ClassVar[tuple[str, ...]] = ()
40 coord: Any | None
42 def __repr__(self):
43 """Generates a python representation of the current node"""
44 result = self.__class__.__name__ + "("
46 indent = ""
47 separator = ""
48 for name in self.__slots__[:-2]:
49 result += separator
50 result += indent
51 result += (
52 name
53 + "="
54 + (
55 _repr(getattr(self, name)).replace(
56 "\n",
57 "\n " + (" " * (len(name) + len(self.__class__.__name__))),
58 )
59 )
60 )
62 separator = ","
63 indent = "\n " + (" " * len(self.__class__.__name__))
65 result += indent + ")"
67 return result
69 def children(self):
70 """Return a tuple of (name, child) pairs for immediate child nodes.
72 Names identify the field and, for list fields, the index, such as
73 "type" or "ext[0]". Optional children that are None are omitted.
74 The returned tuple supports len() and indexing. Iterating over the
75 node itself yields just the child nodes, without their names.
76 """
78 def show(
79 self,
80 buf: IO[str] = sys.stdout,
81 offset: int = 0,
82 attrnames: bool = False,
83 showemptyattrs: bool = True,
84 nodenames: bool = False,
85 showcoord: bool = False,
86 _my_node_name: str | None = None,
87 ):
88 """Pretty print the Node and all its attributes and
89 children (recursively) to a buffer.
91 buf:
92 Open IO buffer into which the Node is printed.
94 offset:
95 Initial offset (amount of leading spaces)
97 attrnames:
98 True if you want to see the attribute names in
99 name=value pairs. False to only see the values.
101 showemptyattrs:
102 False if you want to suppress printing empty attributes.
104 nodenames:
105 True if you want to see the actual node names
106 within their parents.
108 showcoord:
109 Do you want the coordinates of each Node to be
110 displayed.
111 """
112 lead = " " * offset
113 if nodenames and _my_node_name is not None:
114 buf.write(lead + self.__class__.__name__ + " <" + _my_node_name + ">: ")
115 else:
116 buf.write(lead + self.__class__.__name__ + ": ")
118 if self.attr_names:
120 def is_empty(v):
121 return v is None or (hasattr(v, "__len__") and len(v) == 0)
123 nvlist = [
124 (n, getattr(self, n))
125 for n in self.attr_names
126 if showemptyattrs or not is_empty(getattr(self, n))
127 ]
128 if attrnames:
129 attrstr = ", ".join(f"{name}={value}" for name, value in nvlist)
130 else:
131 attrstr = ", ".join(f"{value}" for _, value in nvlist)
132 buf.write(attrstr)
134 if showcoord:
135 buf.write(f" (at {self.coord})")
136 buf.write("\n")
138 for child_name, child in self.children():
139 child.show(
140 buf,
141 offset=offset + 2,
142 attrnames=attrnames,
143 showemptyattrs=showemptyattrs,
144 nodenames=nodenames,
145 showcoord=showcoord,
146 _my_node_name=child_name,
147 )
150class NodeVisitor:
151 """A base NodeVisitor class for visiting c_ast nodes.
152 Subclass it and define your own visit_XXX methods, where
153 XXX is the class name you want to visit with these
154 methods.
156 For example:
158 class ConstantVisitor(NodeVisitor):
159 def __init__(self):
160 self.values = []
162 def visit_Constant(self, node):
163 self.values.append(node.value)
165 Creates a list of values of all the constant nodes
166 encountered below the given node. To use it:
168 cv = ConstantVisitor()
169 cv.visit(node)
171 Notes:
173 * generic_visit() will be called for AST nodes for which
174 no visit_XXX method was defined.
175 * The children of nodes for which a visit_XXX was
176 defined will not be visited - if you need this, call
177 generic_visit() on the node.
178 You can use:
179 NodeVisitor.generic_visit(self, node)
180 * Modeled after Python's own AST visiting facilities
181 (the ast module of Python 3.0)
182 """
184 _method_cache = None
186 def visit(self, node: Node):
187 """Visit a node."""
189 if self._method_cache is None:
190 self._method_cache = {}
192 visitor = self._method_cache.get(node.__class__.__name__, None)
193 if visitor is None:
194 method = "visit_" + node.__class__.__name__
195 visitor = getattr(self, method, self.generic_visit)
196 self._method_cache[node.__class__.__name__] = visitor
198 return visitor(node)
200 def generic_visit(self, node: Node):
201 """Called if no explicit visitor function exists for a
202 node. Implements preorder visiting of the node.
203 """
204 for _, c in node.children():
205 self.visit(c)
208class ArrayDecl(Node):
209 __slots__ = ("type", "dim", "dim_quals", "attributes", "coord", "__weakref__")
211 def __init__(self, type, dim, dim_quals, coord=None, *, attributes=None):
212 self.type = type
213 self.dim = dim
214 self.dim_quals = dim_quals
215 self.attributes = [] if attributes is None else attributes
216 self.coord = coord
218 def children(self):
219 nodelist = []
220 if self.type is not None:
221 nodelist.append(("type", self.type))
222 if self.dim is not None:
223 nodelist.append(("dim", self.dim))
224 for i, child in enumerate(self.attributes or []):
225 nodelist.append((f"attributes[{i}]", child))
226 return tuple(nodelist)
228 def __iter__(self):
229 if self.type is not None:
230 yield self.type
231 if self.dim is not None:
232 yield self.dim
233 yield from self.attributes or []
235 attr_names = ("dim_quals",)
238class ArrayDesignator(Node):
239 __slots__ = ("expr", "coord", "__weakref__")
241 def __init__(self, expr, coord=None):
242 self.expr = expr
243 self.coord = coord
245 def children(self):
246 nodelist = []
247 if self.expr is not None:
248 nodelist.append(("expr", self.expr))
249 return tuple(nodelist)
251 def __iter__(self):
252 if self.expr is not None:
253 yield self.expr
255 attr_names = ()
258class ArrayRef(Node):
259 __slots__ = ("name", "subscript", "coord", "__weakref__")
261 def __init__(self, name, subscript, coord=None):
262 self.name = name
263 self.subscript = subscript
264 self.coord = coord
266 def children(self):
267 nodelist = []
268 if self.name is not None:
269 nodelist.append(("name", self.name))
270 if self.subscript is not None:
271 nodelist.append(("subscript", self.subscript))
272 return tuple(nodelist)
274 def __iter__(self):
275 if self.name is not None:
276 yield self.name
277 if self.subscript is not None:
278 yield self.subscript
280 attr_names = ()
283class Assignment(Node):
284 __slots__ = ("op", "lvalue", "rvalue", "coord", "__weakref__")
286 def __init__(self, op, lvalue, rvalue, coord=None):
287 self.op = op
288 self.lvalue = lvalue
289 self.rvalue = rvalue
290 self.coord = coord
292 def children(self):
293 nodelist = []
294 if self.lvalue is not None:
295 nodelist.append(("lvalue", self.lvalue))
296 if self.rvalue is not None:
297 nodelist.append(("rvalue", self.rvalue))
298 return tuple(nodelist)
300 def __iter__(self):
301 if self.lvalue is not None:
302 yield self.lvalue
303 if self.rvalue is not None:
304 yield self.rvalue
306 attr_names = ("op",)
309class Alignas(Node):
310 __slots__ = ("alignment", "coord", "__weakref__")
312 def __init__(self, alignment, coord=None):
313 self.alignment = alignment
314 self.coord = coord
316 def children(self):
317 nodelist = []
318 if self.alignment is not None:
319 nodelist.append(("alignment", self.alignment))
320 return tuple(nodelist)
322 def __iter__(self):
323 if self.alignment is not None:
324 yield self.alignment
326 attr_names = ()
329class Attribute(Node):
330 __slots__ = ("name", "namespace", "arguments", "coord", "__weakref__")
332 def __init__(self, name, namespace, arguments, coord=None):
333 self.name = name
334 self.namespace = namespace
335 self.arguments = arguments
336 self.coord = coord
338 def children(self):
339 nodelist = []
340 return tuple(nodelist)
342 def __iter__(self):
343 return
344 yield
346 attr_names = (
347 "name",
348 "namespace",
349 "arguments",
350 )
353class AttributeSpecifier(Node):
354 __slots__ = ("attributes", "coord", "__weakref__")
356 def __init__(self, attributes, coord=None):
357 self.attributes = attributes
358 self.coord = coord
360 def children(self):
361 nodelist = []
362 for i, child in enumerate(self.attributes or []):
363 nodelist.append((f"attributes[{i}]", child))
364 return tuple(nodelist)
366 def __iter__(self):
367 yield from self.attributes or []
369 attr_names = ()
372class AttributeDeclaration(Node):
373 __slots__ = ("attributes", "coord", "__weakref__")
375 def __init__(self, attributes, coord=None):
376 self.attributes = attributes
377 self.coord = coord
379 def children(self):
380 nodelist = []
381 for i, child in enumerate(self.attributes or []):
382 nodelist.append((f"attributes[{i}]", child))
383 return tuple(nodelist)
385 def __iter__(self):
386 yield from self.attributes or []
388 attr_names = ()
391class AttributedStatement(Node):
392 __slots__ = ("attributes", "stmt", "coord", "__weakref__")
394 def __init__(self, attributes, stmt, coord=None):
395 self.attributes = attributes
396 self.stmt = stmt
397 self.coord = coord
399 def children(self):
400 nodelist = []
401 if self.stmt is not None:
402 nodelist.append(("stmt", self.stmt))
403 for i, child in enumerate(self.attributes or []):
404 nodelist.append((f"attributes[{i}]", child))
405 return tuple(nodelist)
407 def __iter__(self):
408 if self.stmt is not None:
409 yield self.stmt
410 yield from self.attributes or []
412 attr_names = ()
415class AttributedType(Node):
416 __slots__ = ("type", "attributes", "coord", "__weakref__")
418 def __init__(self, type, attributes, coord=None):
419 self.type = type
420 self.attributes = attributes
421 self.coord = coord
423 def children(self):
424 nodelist = []
425 if self.type is not None:
426 nodelist.append(("type", self.type))
427 for i, child in enumerate(self.attributes or []):
428 nodelist.append((f"attributes[{i}]", child))
429 return tuple(nodelist)
431 def __iter__(self):
432 if self.type is not None:
433 yield self.type
434 yield from self.attributes or []
436 attr_names = ()
439class BinaryOp(Node):
440 __slots__ = ("op", "left", "right", "coord", "__weakref__")
442 def __init__(self, op, left, right, coord=None):
443 self.op = op
444 self.left = left
445 self.right = right
446 self.coord = coord
448 def children(self):
449 nodelist = []
450 if self.left is not None:
451 nodelist.append(("left", self.left))
452 if self.right is not None:
453 nodelist.append(("right", self.right))
454 return tuple(nodelist)
456 def __iter__(self):
457 if self.left is not None:
458 yield self.left
459 if self.right is not None:
460 yield self.right
462 attr_names = ("op",)
465class BitIntType(Node):
466 __slots__ = ("width", "signedness", "coord", "__weakref__")
468 def __init__(self, width, signedness, coord=None):
469 self.width = width
470 self.signedness = signedness
471 self.coord = coord
473 def children(self):
474 nodelist = []
475 if self.width is not None:
476 nodelist.append(("width", self.width))
477 return tuple(nodelist)
479 def __iter__(self):
480 if self.width is not None:
481 yield self.width
483 attr_names = ("signedness",)
486class Break(Node):
487 __slots__ = ("coord", "__weakref__")
489 def __init__(self, coord=None):
490 self.coord = coord
492 def children(self):
493 return ()
495 def __iter__(self):
496 return
497 yield
499 attr_names = ()
502class Case(Node):
503 __slots__ = ("expr", "stmts", "attributes", "coord", "__weakref__")
505 def __init__(self, expr, stmts, coord=None, *, attributes=None):
506 self.expr = expr
507 self.stmts = stmts
508 self.attributes = [] if attributes is None else attributes
509 self.coord = coord
511 def children(self):
512 nodelist = []
513 if self.expr is not None:
514 nodelist.append(("expr", self.expr))
515 for i, child in enumerate(self.stmts or []):
516 nodelist.append((f"stmts[{i}]", child))
517 for i, child in enumerate(self.attributes or []):
518 nodelist.append((f"attributes[{i}]", child))
519 return tuple(nodelist)
521 def __iter__(self):
522 if self.expr is not None:
523 yield self.expr
524 yield from self.stmts or []
525 yield from self.attributes or []
527 attr_names = ()
530class Cast(Node):
531 __slots__ = ("to_type", "expr", "coord", "__weakref__")
533 def __init__(self, to_type, expr, coord=None):
534 self.to_type = to_type
535 self.expr = expr
536 self.coord = coord
538 def children(self):
539 nodelist = []
540 if self.to_type is not None:
541 nodelist.append(("to_type", self.to_type))
542 if self.expr is not None:
543 nodelist.append(("expr", self.expr))
544 return tuple(nodelist)
546 def __iter__(self):
547 if self.to_type is not None:
548 yield self.to_type
549 if self.expr is not None:
550 yield self.expr
552 attr_names = ()
555class Compound(Node):
556 __slots__ = ("block_items", "coord", "__weakref__")
558 def __init__(self, block_items, coord=None):
559 self.block_items = block_items
560 self.coord = coord
562 def children(self):
563 nodelist = []
564 for i, child in enumerate(self.block_items or []):
565 nodelist.append((f"block_items[{i}]", child))
566 return tuple(nodelist)
568 def __iter__(self):
569 yield from self.block_items or []
571 attr_names = ()
574class CompoundLiteral(Node):
575 __slots__ = ("type", "init", "storage", "coord", "__weakref__")
577 def __init__(self, type, init, storage, coord=None):
578 self.type = type
579 self.init = init
580 self.storage = storage
581 self.coord = coord
583 def children(self):
584 nodelist = []
585 if self.type is not None:
586 nodelist.append(("type", self.type))
587 if self.init is not None:
588 nodelist.append(("init", self.init))
589 return tuple(nodelist)
591 def __iter__(self):
592 if self.type is not None:
593 yield self.type
594 if self.init is not None:
595 yield self.init
597 attr_names = ("storage",)
600class Constant(Node):
601 __slots__ = ("type", "value", "coord", "__weakref__")
603 def __init__(self, type, value, coord=None):
604 self.type = type
605 self.value = value
606 self.coord = coord
608 def children(self):
609 nodelist = []
610 return tuple(nodelist)
612 def __iter__(self):
613 return
614 yield
616 attr_names = (
617 "type",
618 "value",
619 )
622class Continue(Node):
623 __slots__ = ("coord", "__weakref__")
625 def __init__(self, coord=None):
626 self.coord = coord
628 def children(self):
629 return ()
631 def __iter__(self):
632 return
633 yield
635 attr_names = ()
638class Decl(Node):
639 __slots__ = (
640 "name",
641 "quals",
642 "align",
643 "storage",
644 "funcspec",
645 "type",
646 "init",
647 "bitsize",
648 "attributes",
649 "coord",
650 "__weakref__",
651 )
653 def __init__(
654 self,
655 name,
656 quals,
657 align,
658 storage,
659 funcspec,
660 type,
661 init,
662 bitsize,
663 coord=None,
664 *,
665 attributes=None,
666 ):
667 self.name = name
668 self.quals = quals
669 self.align = align
670 self.storage = storage
671 self.funcspec = funcspec
672 self.type = type
673 self.init = init
674 self.bitsize = bitsize
675 self.attributes = [] if attributes is None else attributes
676 self.coord = coord
678 def children(self):
679 nodelist = []
680 if self.type is not None:
681 nodelist.append(("type", self.type))
682 if self.init is not None:
683 nodelist.append(("init", self.init))
684 if self.bitsize is not None:
685 nodelist.append(("bitsize", self.bitsize))
686 for i, child in enumerate(self.attributes or []):
687 nodelist.append((f"attributes[{i}]", child))
688 return tuple(nodelist)
690 def __iter__(self):
691 if self.type is not None:
692 yield self.type
693 if self.init is not None:
694 yield self.init
695 if self.bitsize is not None:
696 yield self.bitsize
697 yield from self.attributes or []
699 attr_names = (
700 "name",
701 "quals",
702 "align",
703 "storage",
704 "funcspec",
705 )
708class DeclList(Node):
709 __slots__ = ("decls", "coord", "__weakref__")
711 def __init__(self, decls, coord=None):
712 self.decls = decls
713 self.coord = coord
715 def children(self):
716 nodelist = []
717 for i, child in enumerate(self.decls or []):
718 nodelist.append((f"decls[{i}]", child))
719 return tuple(nodelist)
721 def __iter__(self):
722 yield from self.decls or []
724 attr_names = ()
727class Default(Node):
728 __slots__ = ("stmts", "attributes", "coord", "__weakref__")
730 def __init__(self, stmts, coord=None, *, attributes=None):
731 self.stmts = stmts
732 self.attributes = [] if attributes is None else attributes
733 self.coord = coord
735 def children(self):
736 nodelist = []
737 for i, child in enumerate(self.stmts or []):
738 nodelist.append((f"stmts[{i}]", child))
739 for i, child in enumerate(self.attributes or []):
740 nodelist.append((f"attributes[{i}]", child))
741 return tuple(nodelist)
743 def __iter__(self):
744 yield from self.stmts or []
745 yield from self.attributes or []
747 attr_names = ()
750class DoWhile(Node):
751 __slots__ = ("cond", "stmt", "coord", "__weakref__")
753 def __init__(self, cond, stmt, coord=None):
754 self.cond = cond
755 self.stmt = stmt
756 self.coord = coord
758 def children(self):
759 nodelist = []
760 if self.cond is not None:
761 nodelist.append(("cond", self.cond))
762 if self.stmt is not None:
763 nodelist.append(("stmt", self.stmt))
764 return tuple(nodelist)
766 def __iter__(self):
767 if self.cond is not None:
768 yield self.cond
769 if self.stmt is not None:
770 yield self.stmt
772 attr_names = ()
775class EllipsisParam(Node):
776 __slots__ = ("coord", "__weakref__")
778 def __init__(self, coord=None):
779 self.coord = coord
781 def children(self):
782 return ()
784 def __iter__(self):
785 return
786 yield
788 attr_names = ()
791class EmptyStatement(Node):
792 __slots__ = ("coord", "__weakref__")
794 def __init__(self, coord=None):
795 self.coord = coord
797 def children(self):
798 return ()
800 def __iter__(self):
801 return
802 yield
804 attr_names = ()
807class Enum(Node):
808 __slots__ = (
809 "name",
810 "values",
811 "underlying_type",
812 "attributes",
813 "coord",
814 "__weakref__",
815 )
817 def __init__(self, name, values, underlying_type, coord=None, *, attributes=None):
818 self.name = name
819 self.values = values
820 self.underlying_type = underlying_type
821 self.attributes = [] if attributes is None else attributes
822 self.coord = coord
824 def children(self):
825 nodelist = []
826 if self.values is not None:
827 nodelist.append(("values", self.values))
828 if self.underlying_type is not None:
829 nodelist.append(("underlying_type", self.underlying_type))
830 for i, child in enumerate(self.attributes or []):
831 nodelist.append((f"attributes[{i}]", child))
832 return tuple(nodelist)
834 def __iter__(self):
835 if self.values is not None:
836 yield self.values
837 if self.underlying_type is not None:
838 yield self.underlying_type
839 yield from self.attributes or []
841 attr_names = ("name",)
844class Enumerator(Node):
845 __slots__ = ("name", "value", "attributes", "coord", "__weakref__")
847 def __init__(self, name, value, coord=None, *, attributes=None):
848 self.name = name
849 self.value = value
850 self.attributes = [] if attributes is None else attributes
851 self.coord = coord
853 def children(self):
854 nodelist = []
855 if self.value is not None:
856 nodelist.append(("value", self.value))
857 for i, child in enumerate(self.attributes or []):
858 nodelist.append((f"attributes[{i}]", child))
859 return tuple(nodelist)
861 def __iter__(self):
862 if self.value is not None:
863 yield self.value
864 yield from self.attributes or []
866 attr_names = ("name",)
869class EnumeratorList(Node):
870 __slots__ = ("enumerators", "coord", "__weakref__")
872 def __init__(self, enumerators, coord=None):
873 self.enumerators = enumerators
874 self.coord = coord
876 def children(self):
877 nodelist = []
878 for i, child in enumerate(self.enumerators or []):
879 nodelist.append((f"enumerators[{i}]", child))
880 return tuple(nodelist)
882 def __iter__(self):
883 yield from self.enumerators or []
885 attr_names = ()
888class ExprList(Node):
889 __slots__ = ("exprs", "coord", "__weakref__")
891 def __init__(self, exprs, coord=None):
892 self.exprs = exprs
893 self.coord = coord
895 def children(self):
896 nodelist = []
897 for i, child in enumerate(self.exprs or []):
898 nodelist.append((f"exprs[{i}]", child))
899 return tuple(nodelist)
901 def __iter__(self):
902 yield from self.exprs or []
904 attr_names = ()
907class FileAST(Node):
908 __slots__ = ("ext", "coord", "__weakref__")
910 def __init__(self, ext, coord=None):
911 self.ext = ext
912 self.coord = coord
914 def children(self):
915 nodelist = []
916 for i, child in enumerate(self.ext or []):
917 nodelist.append((f"ext[{i}]", child))
918 return tuple(nodelist)
920 def __iter__(self):
921 yield from self.ext or []
923 attr_names = ()
926class For(Node):
927 __slots__ = ("init", "cond", "next", "stmt", "coord", "__weakref__")
929 def __init__(self, init, cond, next, stmt, coord=None):
930 self.init = init
931 self.cond = cond
932 self.next = next
933 self.stmt = stmt
934 self.coord = coord
936 def children(self):
937 nodelist = []
938 if self.init is not None:
939 nodelist.append(("init", self.init))
940 if self.cond is not None:
941 nodelist.append(("cond", self.cond))
942 if self.next is not None:
943 nodelist.append(("next", self.next))
944 if self.stmt is not None:
945 nodelist.append(("stmt", self.stmt))
946 return tuple(nodelist)
948 def __iter__(self):
949 if self.init is not None:
950 yield self.init
951 if self.cond is not None:
952 yield self.cond
953 if self.next is not None:
954 yield self.next
955 if self.stmt is not None:
956 yield self.stmt
958 attr_names = ()
961class FuncCall(Node):
962 __slots__ = ("name", "args", "coord", "__weakref__")
964 def __init__(self, name, args, coord=None):
965 self.name = name
966 self.args = args
967 self.coord = coord
969 def children(self):
970 nodelist = []
971 if self.name is not None:
972 nodelist.append(("name", self.name))
973 if self.args is not None:
974 nodelist.append(("args", self.args))
975 return tuple(nodelist)
977 def __iter__(self):
978 if self.name is not None:
979 yield self.name
980 if self.args is not None:
981 yield self.args
983 attr_names = ()
986class FuncDecl(Node):
987 __slots__ = ("args", "type", "attributes", "coord", "__weakref__")
989 def __init__(self, args, type, coord=None, *, attributes=None):
990 self.args = args
991 self.type = type
992 self.attributes = [] if attributes is None else attributes
993 self.coord = coord
995 def children(self):
996 nodelist = []
997 if self.args is not None:
998 nodelist.append(("args", self.args))
999 if self.type is not None:
1000 nodelist.append(("type", self.type))
1001 for i, child in enumerate(self.attributes or []):
1002 nodelist.append((f"attributes[{i}]", child))
1003 return tuple(nodelist)
1005 def __iter__(self):
1006 if self.args is not None:
1007 yield self.args
1008 if self.type is not None:
1009 yield self.type
1010 yield from self.attributes or []
1012 attr_names = ()
1015class FuncDef(Node):
1016 __slots__ = ("decl", "param_decls", "body", "coord", "__weakref__")
1018 def __init__(self, decl, param_decls, body, coord=None):
1019 self.decl = decl
1020 self.param_decls = param_decls
1021 self.body = body
1022 self.coord = coord
1024 def children(self):
1025 nodelist = []
1026 if self.decl is not None:
1027 nodelist.append(("decl", self.decl))
1028 if self.body is not None:
1029 nodelist.append(("body", self.body))
1030 for i, child in enumerate(self.param_decls or []):
1031 nodelist.append((f"param_decls[{i}]", child))
1032 return tuple(nodelist)
1034 def __iter__(self):
1035 if self.decl is not None:
1036 yield self.decl
1037 if self.body is not None:
1038 yield self.body
1039 yield from self.param_decls or []
1041 attr_names = ()
1044class GenericAssociation(Node):
1045 __slots__ = ("type", "expr", "coord", "__weakref__")
1047 def __init__(self, type, expr, coord=None):
1048 self.type = type
1049 self.expr = expr
1050 self.coord = coord
1052 def children(self):
1053 nodelist = []
1054 if self.type is not None:
1055 nodelist.append(("type", self.type))
1056 if self.expr is not None:
1057 nodelist.append(("expr", self.expr))
1058 return tuple(nodelist)
1060 def __iter__(self):
1061 if self.type is not None:
1062 yield self.type
1063 if self.expr is not None:
1064 yield self.expr
1066 attr_names = ()
1069class GenericSelection(Node):
1070 __slots__ = ("expr", "associations", "coord", "__weakref__")
1072 def __init__(self, expr, associations, coord=None):
1073 self.expr = expr
1074 self.associations = associations
1075 self.coord = coord
1077 def children(self):
1078 nodelist = []
1079 if self.expr is not None:
1080 nodelist.append(("expr", self.expr))
1081 for i, child in enumerate(self.associations or []):
1082 nodelist.append((f"associations[{i}]", child))
1083 return tuple(nodelist)
1085 def __iter__(self):
1086 if self.expr is not None:
1087 yield self.expr
1088 yield from self.associations or []
1090 attr_names = ()
1093class Goto(Node):
1094 __slots__ = ("name", "coord", "__weakref__")
1096 def __init__(self, name, coord=None):
1097 self.name = name
1098 self.coord = coord
1100 def children(self):
1101 nodelist = []
1102 return tuple(nodelist)
1104 def __iter__(self):
1105 return
1106 yield
1108 attr_names = ("name",)
1111class ID(Node):
1112 __slots__ = ("name", "coord", "__weakref__")
1114 def __init__(self, name, coord=None):
1115 self.name = name
1116 self.coord = coord
1118 def children(self):
1119 nodelist = []
1120 return tuple(nodelist)
1122 def __iter__(self):
1123 return
1124 yield
1126 attr_names = ("name",)
1129class IdentifierType(Node):
1130 __slots__ = ("names", "coord", "__weakref__")
1132 def __init__(self, names, coord=None):
1133 self.names = names
1134 self.coord = coord
1136 def children(self):
1137 nodelist = []
1138 return tuple(nodelist)
1140 def __iter__(self):
1141 return
1142 yield
1144 attr_names = ("names",)
1147class If(Node):
1148 __slots__ = ("cond", "iftrue", "iffalse", "coord", "__weakref__")
1150 def __init__(self, cond, iftrue, iffalse, coord=None):
1151 self.cond = cond
1152 self.iftrue = iftrue
1153 self.iffalse = iffalse
1154 self.coord = coord
1156 def children(self):
1157 nodelist = []
1158 if self.cond is not None:
1159 nodelist.append(("cond", self.cond))
1160 if self.iftrue is not None:
1161 nodelist.append(("iftrue", self.iftrue))
1162 if self.iffalse is not None:
1163 nodelist.append(("iffalse", self.iffalse))
1164 return tuple(nodelist)
1166 def __iter__(self):
1167 if self.cond is not None:
1168 yield self.cond
1169 if self.iftrue is not None:
1170 yield self.iftrue
1171 if self.iffalse is not None:
1172 yield self.iffalse
1174 attr_names = ()
1177class InferredType(Node):
1178 __slots__ = ("coord", "__weakref__")
1180 def __init__(self, coord=None):
1181 self.coord = coord
1183 def children(self):
1184 return ()
1186 def __iter__(self):
1187 return
1188 yield
1190 attr_names = ()
1193class InitList(Node):
1194 __slots__ = ("exprs", "coord", "__weakref__")
1196 def __init__(self, exprs, coord=None):
1197 self.exprs = exprs
1198 self.coord = coord
1200 def children(self):
1201 nodelist = []
1202 for i, child in enumerate(self.exprs or []):
1203 nodelist.append((f"exprs[{i}]", child))
1204 return tuple(nodelist)
1206 def __iter__(self):
1207 yield from self.exprs or []
1209 attr_names = ()
1212class Label(Node):
1213 __slots__ = ("name", "stmt", "attributes", "coord", "__weakref__")
1215 def __init__(self, name, stmt, coord=None, *, attributes=None):
1216 self.name = name
1217 self.stmt = stmt
1218 self.attributes = [] if attributes is None else attributes
1219 self.coord = coord
1221 def children(self):
1222 nodelist = []
1223 if self.stmt is not None:
1224 nodelist.append(("stmt", self.stmt))
1225 for i, child in enumerate(self.attributes or []):
1226 nodelist.append((f"attributes[{i}]", child))
1227 return tuple(nodelist)
1229 def __iter__(self):
1230 if self.stmt is not None:
1231 yield self.stmt
1232 yield from self.attributes or []
1234 attr_names = ("name",)
1237class NamedInitializer(Node):
1238 __slots__ = ("name", "expr", "coord", "__weakref__")
1240 def __init__(self, name, expr, coord=None):
1241 self.name = name
1242 self.expr = expr
1243 self.coord = coord
1245 def children(self):
1246 nodelist = []
1247 if self.expr is not None:
1248 nodelist.append(("expr", self.expr))
1249 for i, child in enumerate(self.name or []):
1250 nodelist.append((f"name[{i}]", child))
1251 return tuple(nodelist)
1253 def __iter__(self):
1254 if self.expr is not None:
1255 yield self.expr
1256 yield from self.name or []
1258 attr_names = ()
1261class ParamList(Node):
1262 __slots__ = ("params", "coord", "__weakref__")
1264 def __init__(self, params, coord=None):
1265 self.params = params
1266 self.coord = coord
1268 def children(self):
1269 nodelist = []
1270 for i, child in enumerate(self.params or []):
1271 nodelist.append((f"params[{i}]", child))
1272 return tuple(nodelist)
1274 def __iter__(self):
1275 yield from self.params or []
1277 attr_names = ()
1280class PtrDecl(Node):
1281 __slots__ = ("quals", "type", "attributes", "coord", "__weakref__")
1283 def __init__(self, quals, type, coord=None, *, attributes=None):
1284 self.quals = quals
1285 self.type = type
1286 self.attributes = [] if attributes is None else attributes
1287 self.coord = coord
1289 def children(self):
1290 nodelist = []
1291 if self.type is not None:
1292 nodelist.append(("type", self.type))
1293 for i, child in enumerate(self.attributes or []):
1294 nodelist.append((f"attributes[{i}]", child))
1295 return tuple(nodelist)
1297 def __iter__(self):
1298 if self.type is not None:
1299 yield self.type
1300 yield from self.attributes or []
1302 attr_names = ("quals",)
1305class Return(Node):
1306 __slots__ = ("expr", "coord", "__weakref__")
1308 def __init__(self, expr, coord=None):
1309 self.expr = expr
1310 self.coord = coord
1312 def children(self):
1313 nodelist = []
1314 if self.expr is not None:
1315 nodelist.append(("expr", self.expr))
1316 return tuple(nodelist)
1318 def __iter__(self):
1319 if self.expr is not None:
1320 yield self.expr
1322 attr_names = ()
1325class StaticAssert(Node):
1326 __slots__ = ("cond", "message", "coord", "__weakref__")
1328 def __init__(self, cond, message, coord=None):
1329 self.cond = cond
1330 self.message = message
1331 self.coord = coord
1333 def children(self):
1334 nodelist = []
1335 if self.cond is not None:
1336 nodelist.append(("cond", self.cond))
1337 if self.message is not None:
1338 nodelist.append(("message", self.message))
1339 return tuple(nodelist)
1341 def __iter__(self):
1342 if self.cond is not None:
1343 yield self.cond
1344 if self.message is not None:
1345 yield self.message
1347 attr_names = ()
1350class Struct(Node):
1351 __slots__ = ("name", "decls", "attributes", "coord", "__weakref__")
1353 def __init__(self, name, decls, coord=None, *, attributes=None):
1354 self.name = name
1355 self.decls = decls
1356 self.attributes = [] if attributes is None else attributes
1357 self.coord = coord
1359 def children(self):
1360 nodelist = []
1361 for i, child in enumerate(self.decls or []):
1362 nodelist.append((f"decls[{i}]", child))
1363 for i, child in enumerate(self.attributes or []):
1364 nodelist.append((f"attributes[{i}]", child))
1365 return tuple(nodelist)
1367 def __iter__(self):
1368 yield from self.decls or []
1369 yield from self.attributes or []
1371 attr_names = ("name",)
1374class StructRef(Node):
1375 __slots__ = ("name", "type", "field", "coord", "__weakref__")
1377 def __init__(self, name, type, field, coord=None):
1378 self.name = name
1379 self.type = type
1380 self.field = field
1381 self.coord = coord
1383 def children(self):
1384 nodelist = []
1385 if self.name is not None:
1386 nodelist.append(("name", self.name))
1387 if self.field is not None:
1388 nodelist.append(("field", self.field))
1389 return tuple(nodelist)
1391 def __iter__(self):
1392 if self.name is not None:
1393 yield self.name
1394 if self.field is not None:
1395 yield self.field
1397 attr_names = ("type",)
1400class Switch(Node):
1401 __slots__ = ("cond", "stmt", "coord", "__weakref__")
1403 def __init__(self, cond, stmt, coord=None):
1404 self.cond = cond
1405 self.stmt = stmt
1406 self.coord = coord
1408 def children(self):
1409 nodelist = []
1410 if self.cond is not None:
1411 nodelist.append(("cond", self.cond))
1412 if self.stmt is not None:
1413 nodelist.append(("stmt", self.stmt))
1414 return tuple(nodelist)
1416 def __iter__(self):
1417 if self.cond is not None:
1418 yield self.cond
1419 if self.stmt is not None:
1420 yield self.stmt
1422 attr_names = ()
1425class TernaryOp(Node):
1426 __slots__ = ("cond", "iftrue", "iffalse", "coord", "__weakref__")
1428 def __init__(self, cond, iftrue, iffalse, coord=None):
1429 self.cond = cond
1430 self.iftrue = iftrue
1431 self.iffalse = iffalse
1432 self.coord = coord
1434 def children(self):
1435 nodelist = []
1436 if self.cond is not None:
1437 nodelist.append(("cond", self.cond))
1438 if self.iftrue is not None:
1439 nodelist.append(("iftrue", self.iftrue))
1440 if self.iffalse is not None:
1441 nodelist.append(("iffalse", self.iffalse))
1442 return tuple(nodelist)
1444 def __iter__(self):
1445 if self.cond is not None:
1446 yield self.cond
1447 if self.iftrue is not None:
1448 yield self.iftrue
1449 if self.iffalse is not None:
1450 yield self.iffalse
1452 attr_names = ()
1455class TypeDecl(Node):
1456 __slots__ = (
1457 "declname",
1458 "quals",
1459 "align",
1460 "type",
1461 "attributes",
1462 "coord",
1463 "__weakref__",
1464 )
1466 def __init__(self, declname, quals, align, type, coord=None, *, attributes=None):
1467 self.declname = declname
1468 self.quals = quals
1469 self.align = align
1470 self.type = type
1471 self.attributes = [] if attributes is None else attributes
1472 self.coord = coord
1474 def children(self):
1475 nodelist = []
1476 if self.type is not None:
1477 nodelist.append(("type", self.type))
1478 for i, child in enumerate(self.attributes or []):
1479 nodelist.append((f"attributes[{i}]", child))
1480 return tuple(nodelist)
1482 def __iter__(self):
1483 if self.type is not None:
1484 yield self.type
1485 yield from self.attributes or []
1487 attr_names = (
1488 "declname",
1489 "quals",
1490 "align",
1491 )
1494class Typedef(Node):
1495 __slots__ = (
1496 "name",
1497 "quals",
1498 "storage",
1499 "type",
1500 "attributes",
1501 "coord",
1502 "__weakref__",
1503 )
1505 def __init__(self, name, quals, storage, type, coord=None, *, attributes=None):
1506 self.name = name
1507 self.quals = quals
1508 self.storage = storage
1509 self.type = type
1510 self.attributes = [] if attributes is None else attributes
1511 self.coord = coord
1513 def children(self):
1514 nodelist = []
1515 if self.type is not None:
1516 nodelist.append(("type", self.type))
1517 for i, child in enumerate(self.attributes or []):
1518 nodelist.append((f"attributes[{i}]", child))
1519 return tuple(nodelist)
1521 def __iter__(self):
1522 if self.type is not None:
1523 yield self.type
1524 yield from self.attributes or []
1526 attr_names = (
1527 "name",
1528 "quals",
1529 "storage",
1530 )
1533class Typename(Node):
1534 __slots__ = ("name", "quals", "align", "type", "attributes", "coord", "__weakref__")
1536 def __init__(self, name, quals, align, type, coord=None, *, attributes=None):
1537 self.name = name
1538 self.quals = quals
1539 self.align = align
1540 self.type = type
1541 self.attributes = [] if attributes is None else attributes
1542 self.coord = coord
1544 def children(self):
1545 nodelist = []
1546 if self.type is not None:
1547 nodelist.append(("type", self.type))
1548 for i, child in enumerate(self.attributes or []):
1549 nodelist.append((f"attributes[{i}]", child))
1550 return tuple(nodelist)
1552 def __iter__(self):
1553 if self.type is not None:
1554 yield self.type
1555 yield from self.attributes or []
1557 attr_names = (
1558 "name",
1559 "quals",
1560 "align",
1561 )
1564class TypeOf(Node):
1565 __slots__ = ("op", "expr", "coord", "__weakref__")
1567 def __init__(self, op, expr, coord=None):
1568 self.op = op
1569 self.expr = expr
1570 self.coord = coord
1572 def children(self):
1573 nodelist = []
1574 if self.expr is not None:
1575 nodelist.append(("expr", self.expr))
1576 return tuple(nodelist)
1578 def __iter__(self):
1579 if self.expr is not None:
1580 yield self.expr
1582 attr_names = ("op",)
1585class UnaryOp(Node):
1586 __slots__ = ("op", "expr", "coord", "__weakref__")
1588 def __init__(self, op, expr, coord=None):
1589 self.op = op
1590 self.expr = expr
1591 self.coord = coord
1593 def children(self):
1594 nodelist = []
1595 if self.expr is not None:
1596 nodelist.append(("expr", self.expr))
1597 return tuple(nodelist)
1599 def __iter__(self):
1600 if self.expr is not None:
1601 yield self.expr
1603 attr_names = ("op",)
1606class Union(Node):
1607 __slots__ = ("name", "decls", "attributes", "coord", "__weakref__")
1609 def __init__(self, name, decls, coord=None, *, attributes=None):
1610 self.name = name
1611 self.decls = decls
1612 self.attributes = [] if attributes is None else attributes
1613 self.coord = coord
1615 def children(self):
1616 nodelist = []
1617 for i, child in enumerate(self.decls or []):
1618 nodelist.append((f"decls[{i}]", child))
1619 for i, child in enumerate(self.attributes or []):
1620 nodelist.append((f"attributes[{i}]", child))
1621 return tuple(nodelist)
1623 def __iter__(self):
1624 yield from self.decls or []
1625 yield from self.attributes or []
1627 attr_names = ("name",)
1630class While(Node):
1631 __slots__ = ("cond", "stmt", "coord", "__weakref__")
1633 def __init__(self, cond, stmt, coord=None):
1634 self.cond = cond
1635 self.stmt = stmt
1636 self.coord = coord
1638 def children(self):
1639 nodelist = []
1640 if self.cond is not None:
1641 nodelist.append(("cond", self.cond))
1642 if self.stmt is not None:
1643 nodelist.append(("stmt", self.stmt))
1644 return tuple(nodelist)
1646 def __iter__(self):
1647 if self.cond is not None:
1648 yield self.cond
1649 if self.stmt is not None:
1650 yield self.stmt
1652 attr_names = ()
1655class Pragma(Node):
1656 __slots__ = ("string", "coord", "__weakref__")
1658 def __init__(self, string, coord=None):
1659 self.string = string
1660 self.coord = coord
1662 def children(self):
1663 nodelist = []
1664 return tuple(nodelist)
1666 def __iter__(self):
1667 return
1668 yield
1670 attr_names = ("string",)