Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pycparser/c_ast.py: 52%
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# 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 """A sequence of all children that are Nodes"""
72 def show(
73 self,
74 buf: IO[str] = sys.stdout,
75 offset: int = 0,
76 attrnames: bool = False,
77 showemptyattrs: bool = True,
78 nodenames: bool = False,
79 showcoord: bool = False,
80 _my_node_name: str | None = None,
81 ):
82 """Pretty print the Node and all its attributes and
83 children (recursively) to a buffer.
85 buf:
86 Open IO buffer into which the Node is printed.
88 offset:
89 Initial offset (amount of leading spaces)
91 attrnames:
92 True if you want to see the attribute names in
93 name=value pairs. False to only see the values.
95 showemptyattrs:
96 False if you want to suppress printing empty attributes.
98 nodenames:
99 True if you want to see the actual node names
100 within their parents.
102 showcoord:
103 Do you want the coordinates of each Node to be
104 displayed.
105 """
106 lead = " " * offset
107 if nodenames and _my_node_name is not None:
108 buf.write(lead + self.__class__.__name__ + " <" + _my_node_name + ">: ")
109 else:
110 buf.write(lead + self.__class__.__name__ + ": ")
112 if self.attr_names:
114 def is_empty(v):
115 return v is None or (hasattr(v, "__len__") and len(v) == 0)
117 nvlist = [
118 (n, getattr(self, n))
119 for n in self.attr_names
120 if showemptyattrs or not is_empty(getattr(self, n))
121 ]
122 if attrnames:
123 attrstr = ", ".join(f"{name}={value}" for name, value in nvlist)
124 else:
125 attrstr = ", ".join(f"{value}" for _, value in nvlist)
126 buf.write(attrstr)
128 if showcoord:
129 buf.write(f" (at {self.coord})")
130 buf.write("\n")
132 for child_name, child in self.children():
133 child.show(
134 buf,
135 offset=offset + 2,
136 attrnames=attrnames,
137 showemptyattrs=showemptyattrs,
138 nodenames=nodenames,
139 showcoord=showcoord,
140 _my_node_name=child_name,
141 )
144class NodeVisitor:
145 """A base NodeVisitor class for visiting c_ast nodes.
146 Subclass it and define your own visit_XXX methods, where
147 XXX is the class name you want to visit with these
148 methods.
150 For example:
152 class ConstantVisitor(NodeVisitor):
153 def __init__(self):
154 self.values = []
156 def visit_Constant(self, node):
157 self.values.append(node.value)
159 Creates a list of values of all the constant nodes
160 encountered below the given node. To use it:
162 cv = ConstantVisitor()
163 cv.visit(node)
165 Notes:
167 * generic_visit() will be called for AST nodes for which
168 no visit_XXX method was defined.
169 * The children of nodes for which a visit_XXX was
170 defined will not be visited - if you need this, call
171 generic_visit() on the node.
172 You can use:
173 NodeVisitor.generic_visit(self, node)
174 * Modeled after Python's own AST visiting facilities
175 (the ast module of Python 3.0)
176 """
178 _method_cache = None
180 def visit(self, node: Node):
181 """Visit a node."""
183 if self._method_cache is None:
184 self._method_cache = {}
186 visitor = self._method_cache.get(node.__class__.__name__, None)
187 if visitor is None:
188 method = "visit_" + node.__class__.__name__
189 visitor = getattr(self, method, self.generic_visit)
190 self._method_cache[node.__class__.__name__] = visitor
192 return visitor(node)
194 def generic_visit(self, node: Node):
195 """Called if no explicit visitor function exists for a
196 node. Implements preorder visiting of the node.
197 """
198 for _, c in node.children():
199 self.visit(c)
202class ArrayDecl(Node):
203 __slots__ = ("type", "dim", "dim_quals", "coord", "__weakref__")
205 def __init__(self, type, dim, dim_quals, coord=None):
206 self.type = type
207 self.dim = dim
208 self.dim_quals = dim_quals
209 self.coord = coord
211 def children(self):
212 nodelist = []
213 if self.type is not None:
214 nodelist.append(("type", self.type))
215 if self.dim is not None:
216 nodelist.append(("dim", self.dim))
217 return tuple(nodelist)
219 def __iter__(self):
220 if self.type is not None:
221 yield self.type
222 if self.dim is not None:
223 yield self.dim
225 attr_names = ("dim_quals",)
228class ArrayRef(Node):
229 __slots__ = ("name", "subscript", "coord", "__weakref__")
231 def __init__(self, name, subscript, coord=None):
232 self.name = name
233 self.subscript = subscript
234 self.coord = coord
236 def children(self):
237 nodelist = []
238 if self.name is not None:
239 nodelist.append(("name", self.name))
240 if self.subscript is not None:
241 nodelist.append(("subscript", self.subscript))
242 return tuple(nodelist)
244 def __iter__(self):
245 if self.name is not None:
246 yield self.name
247 if self.subscript is not None:
248 yield self.subscript
250 attr_names = ()
253class Assignment(Node):
254 __slots__ = ("op", "lvalue", "rvalue", "coord", "__weakref__")
256 def __init__(self, op, lvalue, rvalue, coord=None):
257 self.op = op
258 self.lvalue = lvalue
259 self.rvalue = rvalue
260 self.coord = coord
262 def children(self):
263 nodelist = []
264 if self.lvalue is not None:
265 nodelist.append(("lvalue", self.lvalue))
266 if self.rvalue is not None:
267 nodelist.append(("rvalue", self.rvalue))
268 return tuple(nodelist)
270 def __iter__(self):
271 if self.lvalue is not None:
272 yield self.lvalue
273 if self.rvalue is not None:
274 yield self.rvalue
276 attr_names = ("op",)
279class Alignas(Node):
280 __slots__ = ("alignment", "coord", "__weakref__")
282 def __init__(self, alignment, coord=None):
283 self.alignment = alignment
284 self.coord = coord
286 def children(self):
287 nodelist = []
288 if self.alignment is not None:
289 nodelist.append(("alignment", self.alignment))
290 return tuple(nodelist)
292 def __iter__(self):
293 if self.alignment is not None:
294 yield self.alignment
296 attr_names = ()
299class BinaryOp(Node):
300 __slots__ = ("op", "left", "right", "coord", "__weakref__")
302 def __init__(self, op, left, right, coord=None):
303 self.op = op
304 self.left = left
305 self.right = right
306 self.coord = coord
308 def children(self):
309 nodelist = []
310 if self.left is not None:
311 nodelist.append(("left", self.left))
312 if self.right is not None:
313 nodelist.append(("right", self.right))
314 return tuple(nodelist)
316 def __iter__(self):
317 if self.left is not None:
318 yield self.left
319 if self.right is not None:
320 yield self.right
322 attr_names = ("op",)
325class Break(Node):
326 __slots__ = ("coord", "__weakref__")
328 def __init__(self, coord=None):
329 self.coord = coord
331 def children(self):
332 return ()
334 def __iter__(self):
335 return
336 yield
338 attr_names = ()
341class Case(Node):
342 __slots__ = ("expr", "stmts", "coord", "__weakref__")
344 def __init__(self, expr, stmts, coord=None):
345 self.expr = expr
346 self.stmts = stmts
347 self.coord = coord
349 def children(self):
350 nodelist = []
351 if self.expr is not None:
352 nodelist.append(("expr", self.expr))
353 for i, child in enumerate(self.stmts or []):
354 nodelist.append((f"stmts[{i}]", child))
355 return tuple(nodelist)
357 def __iter__(self):
358 if self.expr is not None:
359 yield self.expr
360 yield from self.stmts or []
362 attr_names = ()
365class Cast(Node):
366 __slots__ = ("to_type", "expr", "coord", "__weakref__")
368 def __init__(self, to_type, expr, coord=None):
369 self.to_type = to_type
370 self.expr = expr
371 self.coord = coord
373 def children(self):
374 nodelist = []
375 if self.to_type is not None:
376 nodelist.append(("to_type", self.to_type))
377 if self.expr is not None:
378 nodelist.append(("expr", self.expr))
379 return tuple(nodelist)
381 def __iter__(self):
382 if self.to_type is not None:
383 yield self.to_type
384 if self.expr is not None:
385 yield self.expr
387 attr_names = ()
390class Compound(Node):
391 __slots__ = ("block_items", "coord", "__weakref__")
393 def __init__(self, block_items, coord=None):
394 self.block_items = block_items
395 self.coord = coord
397 def children(self):
398 nodelist = []
399 for i, child in enumerate(self.block_items or []):
400 nodelist.append((f"block_items[{i}]", child))
401 return tuple(nodelist)
403 def __iter__(self):
404 yield from self.block_items or []
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 yield from self.decls or []
542 attr_names = ()
545class Default(Node):
546 __slots__ = ("stmts", "coord", "__weakref__")
548 def __init__(self, stmts, coord=None):
549 self.stmts = stmts
550 self.coord = coord
552 def children(self):
553 nodelist = []
554 for i, child in enumerate(self.stmts or []):
555 nodelist.append((f"stmts[{i}]", child))
556 return tuple(nodelist)
558 def __iter__(self):
559 yield from self.stmts or []
561 attr_names = ()
564class DoWhile(Node):
565 __slots__ = ("cond", "stmt", "coord", "__weakref__")
567 def __init__(self, cond, stmt, coord=None):
568 self.cond = cond
569 self.stmt = stmt
570 self.coord = coord
572 def children(self):
573 nodelist = []
574 if self.cond is not None:
575 nodelist.append(("cond", self.cond))
576 if self.stmt is not None:
577 nodelist.append(("stmt", self.stmt))
578 return tuple(nodelist)
580 def __iter__(self):
581 if self.cond is not None:
582 yield self.cond
583 if self.stmt is not None:
584 yield self.stmt
586 attr_names = ()
589class EllipsisParam(Node):
590 __slots__ = ("coord", "__weakref__")
592 def __init__(self, coord=None):
593 self.coord = coord
595 def children(self):
596 return ()
598 def __iter__(self):
599 return
600 yield
602 attr_names = ()
605class EmptyStatement(Node):
606 __slots__ = ("coord", "__weakref__")
608 def __init__(self, coord=None):
609 self.coord = coord
611 def children(self):
612 return ()
614 def __iter__(self):
615 return
616 yield
618 attr_names = ()
621class Enum(Node):
622 __slots__ = ("name", "values", "coord", "__weakref__")
624 def __init__(self, name, values, coord=None):
625 self.name = name
626 self.values = values
627 self.coord = coord
629 def children(self):
630 nodelist = []
631 if self.values is not None:
632 nodelist.append(("values", self.values))
633 return tuple(nodelist)
635 def __iter__(self):
636 if self.values is not None:
637 yield self.values
639 attr_names = ("name",)
642class Enumerator(Node):
643 __slots__ = ("name", "value", "coord", "__weakref__")
645 def __init__(self, name, value, coord=None):
646 self.name = name
647 self.value = value
648 self.coord = coord
650 def children(self):
651 nodelist = []
652 if self.value is not None:
653 nodelist.append(("value", self.value))
654 return tuple(nodelist)
656 def __iter__(self):
657 if self.value is not None:
658 yield self.value
660 attr_names = ("name",)
663class EnumeratorList(Node):
664 __slots__ = ("enumerators", "coord", "__weakref__")
666 def __init__(self, enumerators, coord=None):
667 self.enumerators = enumerators
668 self.coord = coord
670 def children(self):
671 nodelist = []
672 for i, child in enumerate(self.enumerators or []):
673 nodelist.append((f"enumerators[{i}]", child))
674 return tuple(nodelist)
676 def __iter__(self):
677 yield from self.enumerators or []
679 attr_names = ()
682class ExprList(Node):
683 __slots__ = ("exprs", "coord", "__weakref__")
685 def __init__(self, exprs, coord=None):
686 self.exprs = exprs
687 self.coord = coord
689 def children(self):
690 nodelist = []
691 for i, child in enumerate(self.exprs or []):
692 nodelist.append((f"exprs[{i}]", child))
693 return tuple(nodelist)
695 def __iter__(self):
696 yield from self.exprs or []
698 attr_names = ()
701class FileAST(Node):
702 __slots__ = ("ext", "coord", "__weakref__")
704 def __init__(self, ext, coord=None):
705 self.ext = ext
706 self.coord = coord
708 def children(self):
709 nodelist = []
710 for i, child in enumerate(self.ext or []):
711 nodelist.append((f"ext[{i}]", child))
712 return tuple(nodelist)
714 def __iter__(self):
715 yield from self.ext or []
717 attr_names = ()
720class For(Node):
721 __slots__ = ("init", "cond", "next", "stmt", "coord", "__weakref__")
723 def __init__(self, init, cond, next, stmt, coord=None):
724 self.init = init
725 self.cond = cond
726 self.next = next
727 self.stmt = stmt
728 self.coord = coord
730 def children(self):
731 nodelist = []
732 if self.init is not None:
733 nodelist.append(("init", self.init))
734 if self.cond is not None:
735 nodelist.append(("cond", self.cond))
736 if self.next is not None:
737 nodelist.append(("next", self.next))
738 if self.stmt is not None:
739 nodelist.append(("stmt", self.stmt))
740 return tuple(nodelist)
742 def __iter__(self):
743 if self.init is not None:
744 yield self.init
745 if self.cond is not None:
746 yield self.cond
747 if self.next is not None:
748 yield self.next
749 if self.stmt is not None:
750 yield self.stmt
752 attr_names = ()
755class FuncCall(Node):
756 __slots__ = ("name", "args", "coord", "__weakref__")
758 def __init__(self, name, args, coord=None):
759 self.name = name
760 self.args = args
761 self.coord = coord
763 def children(self):
764 nodelist = []
765 if self.name is not None:
766 nodelist.append(("name", self.name))
767 if self.args is not None:
768 nodelist.append(("args", self.args))
769 return tuple(nodelist)
771 def __iter__(self):
772 if self.name is not None:
773 yield self.name
774 if self.args is not None:
775 yield self.args
777 attr_names = ()
780class FuncDecl(Node):
781 __slots__ = ("args", "type", "coord", "__weakref__")
783 def __init__(self, args, type, coord=None):
784 self.args = args
785 self.type = type
786 self.coord = coord
788 def children(self):
789 nodelist = []
790 if self.args is not None:
791 nodelist.append(("args", self.args))
792 if self.type is not None:
793 nodelist.append(("type", self.type))
794 return tuple(nodelist)
796 def __iter__(self):
797 if self.args is not None:
798 yield self.args
799 if self.type is not None:
800 yield self.type
802 attr_names = ()
805class FuncDef(Node):
806 __slots__ = ("decl", "param_decls", "body", "coord", "__weakref__")
808 def __init__(self, decl, param_decls, body, coord=None):
809 self.decl = decl
810 self.param_decls = param_decls
811 self.body = body
812 self.coord = coord
814 def children(self):
815 nodelist = []
816 if self.decl is not None:
817 nodelist.append(("decl", self.decl))
818 if self.body is not None:
819 nodelist.append(("body", self.body))
820 for i, child in enumerate(self.param_decls or []):
821 nodelist.append((f"param_decls[{i}]", child))
822 return tuple(nodelist)
824 def __iter__(self):
825 if self.decl is not None:
826 yield self.decl
827 if self.body is not None:
828 yield self.body
829 yield from self.param_decls or []
831 attr_names = ()
834class Goto(Node):
835 __slots__ = ("name", "coord", "__weakref__")
837 def __init__(self, name, coord=None):
838 self.name = name
839 self.coord = coord
841 def children(self):
842 nodelist = []
843 return tuple(nodelist)
845 def __iter__(self):
846 return
847 yield
849 attr_names = ("name",)
852class ID(Node):
853 __slots__ = ("name", "coord", "__weakref__")
855 def __init__(self, name, coord=None):
856 self.name = name
857 self.coord = coord
859 def children(self):
860 nodelist = []
861 return tuple(nodelist)
863 def __iter__(self):
864 return
865 yield
867 attr_names = ("name",)
870class IdentifierType(Node):
871 __slots__ = ("names", "coord", "__weakref__")
873 def __init__(self, names, coord=None):
874 self.names = names
875 self.coord = coord
877 def children(self):
878 nodelist = []
879 return tuple(nodelist)
881 def __iter__(self):
882 return
883 yield
885 attr_names = ("names",)
888class If(Node):
889 __slots__ = ("cond", "iftrue", "iffalse", "coord", "__weakref__")
891 def __init__(self, cond, iftrue, iffalse, coord=None):
892 self.cond = cond
893 self.iftrue = iftrue
894 self.iffalse = iffalse
895 self.coord = coord
897 def children(self):
898 nodelist = []
899 if self.cond is not None:
900 nodelist.append(("cond", self.cond))
901 if self.iftrue is not None:
902 nodelist.append(("iftrue", self.iftrue))
903 if self.iffalse is not None:
904 nodelist.append(("iffalse", self.iffalse))
905 return tuple(nodelist)
907 def __iter__(self):
908 if self.cond is not None:
909 yield self.cond
910 if self.iftrue is not None:
911 yield self.iftrue
912 if self.iffalse is not None:
913 yield self.iffalse
915 attr_names = ()
918class InitList(Node):
919 __slots__ = ("exprs", "coord", "__weakref__")
921 def __init__(self, exprs, coord=None):
922 self.exprs = exprs
923 self.coord = coord
925 def children(self):
926 nodelist = []
927 for i, child in enumerate(self.exprs or []):
928 nodelist.append((f"exprs[{i}]", child))
929 return tuple(nodelist)
931 def __iter__(self):
932 yield from self.exprs or []
934 attr_names = ()
937class Label(Node):
938 __slots__ = ("name", "stmt", "coord", "__weakref__")
940 def __init__(self, name, stmt, coord=None):
941 self.name = name
942 self.stmt = stmt
943 self.coord = coord
945 def children(self):
946 nodelist = []
947 if self.stmt is not None:
948 nodelist.append(("stmt", self.stmt))
949 return tuple(nodelist)
951 def __iter__(self):
952 if self.stmt is not None:
953 yield self.stmt
955 attr_names = ("name",)
958class NamedInitializer(Node):
959 __slots__ = ("name", "expr", "coord", "__weakref__")
961 def __init__(self, name, expr, coord=None):
962 self.name = name
963 self.expr = expr
964 self.coord = coord
966 def children(self):
967 nodelist = []
968 if self.expr is not None:
969 nodelist.append(("expr", self.expr))
970 for i, child in enumerate(self.name or []):
971 nodelist.append((f"name[{i}]", child))
972 return tuple(nodelist)
974 def __iter__(self):
975 if self.expr is not None:
976 yield self.expr
977 yield from self.name or []
979 attr_names = ()
982class ParamList(Node):
983 __slots__ = ("params", "coord", "__weakref__")
985 def __init__(self, params, coord=None):
986 self.params = params
987 self.coord = coord
989 def children(self):
990 nodelist = []
991 for i, child in enumerate(self.params or []):
992 nodelist.append((f"params[{i}]", child))
993 return tuple(nodelist)
995 def __iter__(self):
996 yield from self.params or []
998 attr_names = ()
1001class PtrDecl(Node):
1002 __slots__ = ("quals", "type", "coord", "__weakref__")
1004 def __init__(self, quals, type, coord=None):
1005 self.quals = quals
1006 self.type = type
1007 self.coord = coord
1009 def children(self):
1010 nodelist = []
1011 if self.type is not None:
1012 nodelist.append(("type", self.type))
1013 return tuple(nodelist)
1015 def __iter__(self):
1016 if self.type is not None:
1017 yield self.type
1019 attr_names = ("quals",)
1022class Return(Node):
1023 __slots__ = ("expr", "coord", "__weakref__")
1025 def __init__(self, expr, coord=None):
1026 self.expr = expr
1027 self.coord = coord
1029 def children(self):
1030 nodelist = []
1031 if self.expr is not None:
1032 nodelist.append(("expr", self.expr))
1033 return tuple(nodelist)
1035 def __iter__(self):
1036 if self.expr is not None:
1037 yield self.expr
1039 attr_names = ()
1042class StaticAssert(Node):
1043 __slots__ = ("cond", "message", "coord", "__weakref__")
1045 def __init__(self, cond, message, coord=None):
1046 self.cond = cond
1047 self.message = message
1048 self.coord = coord
1050 def children(self):
1051 nodelist = []
1052 if self.cond is not None:
1053 nodelist.append(("cond", self.cond))
1054 if self.message is not None:
1055 nodelist.append(("message", self.message))
1056 return tuple(nodelist)
1058 def __iter__(self):
1059 if self.cond is not None:
1060 yield self.cond
1061 if self.message is not None:
1062 yield self.message
1064 attr_names = ()
1067class Struct(Node):
1068 __slots__ = ("name", "decls", "coord", "__weakref__")
1070 def __init__(self, name, decls, coord=None):
1071 self.name = name
1072 self.decls = decls
1073 self.coord = coord
1075 def children(self):
1076 nodelist = []
1077 for i, child in enumerate(self.decls or []):
1078 nodelist.append((f"decls[{i}]", child))
1079 return tuple(nodelist)
1081 def __iter__(self):
1082 yield from self.decls or []
1084 attr_names = ("name",)
1087class StructRef(Node):
1088 __slots__ = ("name", "type", "field", "coord", "__weakref__")
1090 def __init__(self, name, type, field, coord=None):
1091 self.name = name
1092 self.type = type
1093 self.field = field
1094 self.coord = coord
1096 def children(self):
1097 nodelist = []
1098 if self.name is not None:
1099 nodelist.append(("name", self.name))
1100 if self.field is not None:
1101 nodelist.append(("field", self.field))
1102 return tuple(nodelist)
1104 def __iter__(self):
1105 if self.name is not None:
1106 yield self.name
1107 if self.field is not None:
1108 yield self.field
1110 attr_names = ("type",)
1113class Switch(Node):
1114 __slots__ = ("cond", "stmt", "coord", "__weakref__")
1116 def __init__(self, cond, stmt, coord=None):
1117 self.cond = cond
1118 self.stmt = stmt
1119 self.coord = coord
1121 def children(self):
1122 nodelist = []
1123 if self.cond is not None:
1124 nodelist.append(("cond", self.cond))
1125 if self.stmt is not None:
1126 nodelist.append(("stmt", self.stmt))
1127 return tuple(nodelist)
1129 def __iter__(self):
1130 if self.cond is not None:
1131 yield self.cond
1132 if self.stmt is not None:
1133 yield self.stmt
1135 attr_names = ()
1138class TernaryOp(Node):
1139 __slots__ = ("cond", "iftrue", "iffalse", "coord", "__weakref__")
1141 def __init__(self, cond, iftrue, iffalse, coord=None):
1142 self.cond = cond
1143 self.iftrue = iftrue
1144 self.iffalse = iffalse
1145 self.coord = coord
1147 def children(self):
1148 nodelist = []
1149 if self.cond is not None:
1150 nodelist.append(("cond", self.cond))
1151 if self.iftrue is not None:
1152 nodelist.append(("iftrue", self.iftrue))
1153 if self.iffalse is not None:
1154 nodelist.append(("iffalse", self.iffalse))
1155 return tuple(nodelist)
1157 def __iter__(self):
1158 if self.cond is not None:
1159 yield self.cond
1160 if self.iftrue is not None:
1161 yield self.iftrue
1162 if self.iffalse is not None:
1163 yield self.iffalse
1165 attr_names = ()
1168class TypeDecl(Node):
1169 __slots__ = ("declname", "quals", "align", "type", "coord", "__weakref__")
1171 def __init__(self, declname, quals, align, type, coord=None):
1172 self.declname = declname
1173 self.quals = quals
1174 self.align = align
1175 self.type = type
1176 self.coord = coord
1178 def children(self):
1179 nodelist = []
1180 if self.type is not None:
1181 nodelist.append(("type", self.type))
1182 return tuple(nodelist)
1184 def __iter__(self):
1185 if self.type is not None:
1186 yield self.type
1188 attr_names = (
1189 "declname",
1190 "quals",
1191 "align",
1192 )
1195class Typedef(Node):
1196 __slots__ = ("name", "quals", "storage", "type", "coord", "__weakref__")
1198 def __init__(self, name, quals, storage, type, coord=None):
1199 self.name = name
1200 self.quals = quals
1201 self.storage = storage
1202 self.type = type
1203 self.coord = coord
1205 def children(self):
1206 nodelist = []
1207 if self.type is not None:
1208 nodelist.append(("type", self.type))
1209 return tuple(nodelist)
1211 def __iter__(self):
1212 if self.type is not None:
1213 yield self.type
1215 attr_names = (
1216 "name",
1217 "quals",
1218 "storage",
1219 )
1222class Typename(Node):
1223 __slots__ = ("name", "quals", "align", "type", "coord", "__weakref__")
1225 def __init__(self, name, quals, align, type, coord=None):
1226 self.name = name
1227 self.quals = quals
1228 self.align = align
1229 self.type = type
1230 self.coord = coord
1232 def children(self):
1233 nodelist = []
1234 if self.type is not None:
1235 nodelist.append(("type", self.type))
1236 return tuple(nodelist)
1238 def __iter__(self):
1239 if self.type is not None:
1240 yield self.type
1242 attr_names = (
1243 "name",
1244 "quals",
1245 "align",
1246 )
1249class UnaryOp(Node):
1250 __slots__ = ("op", "expr", "coord", "__weakref__")
1252 def __init__(self, op, expr, coord=None):
1253 self.op = op
1254 self.expr = expr
1255 self.coord = coord
1257 def children(self):
1258 nodelist = []
1259 if self.expr is not None:
1260 nodelist.append(("expr", self.expr))
1261 return tuple(nodelist)
1263 def __iter__(self):
1264 if self.expr is not None:
1265 yield self.expr
1267 attr_names = ("op",)
1270class Union(Node):
1271 __slots__ = ("name", "decls", "coord", "__weakref__")
1273 def __init__(self, name, decls, coord=None):
1274 self.name = name
1275 self.decls = decls
1276 self.coord = coord
1278 def children(self):
1279 nodelist = []
1280 for i, child in enumerate(self.decls or []):
1281 nodelist.append((f"decls[{i}]", child))
1282 return tuple(nodelist)
1284 def __iter__(self):
1285 yield from self.decls or []
1287 attr_names = ("name",)
1290class While(Node):
1291 __slots__ = ("cond", "stmt", "coord", "__weakref__")
1293 def __init__(self, cond, stmt, coord=None):
1294 self.cond = cond
1295 self.stmt = stmt
1296 self.coord = coord
1298 def children(self):
1299 nodelist = []
1300 if self.cond is not None:
1301 nodelist.append(("cond", self.cond))
1302 if self.stmt is not None:
1303 nodelist.append(("stmt", self.stmt))
1304 return tuple(nodelist)
1306 def __iter__(self):
1307 if self.cond is not None:
1308 yield self.cond
1309 if self.stmt is not None:
1310 yield self.stmt
1312 attr_names = ()
1315class Pragma(Node):
1316 __slots__ = ("string", "coord", "__weakref__")
1318 def __init__(self, string, coord=None):
1319 self.string = string
1320 self.coord = coord
1322 def children(self):
1323 nodelist = []
1324 return tuple(nodelist)
1326 def __iter__(self):
1327 return
1328 yield
1330 attr_names = ("string",)