You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

c_ast.py 30KB

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