c_ast.py 32 KB

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