c_ast.py 33 KB

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