Sphinx 7.2.6__py3-none-any.whl → 7.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of Sphinx might be problematic. Click here for more details.

Files changed (388) hide show
  1. sphinx/__init__.py +8 -9
  2. sphinx/addnodes.py +31 -28
  3. sphinx/application.py +9 -15
  4. sphinx/builders/__init__.py +5 -6
  5. sphinx/builders/_epub_base.py +17 -9
  6. sphinx/builders/changes.py +10 -5
  7. sphinx/builders/dirhtml.py +4 -2
  8. sphinx/builders/dummy.py +3 -2
  9. sphinx/builders/epub3.py +5 -3
  10. sphinx/builders/gettext.py +24 -7
  11. sphinx/builders/html/__init__.py +88 -96
  12. sphinx/builders/html/_assets.py +16 -16
  13. sphinx/builders/html/transforms.py +4 -2
  14. sphinx/builders/latex/__init__.py +40 -33
  15. sphinx/builders/latex/nodes.py +6 -2
  16. sphinx/builders/latex/transforms.py +17 -8
  17. sphinx/builders/latex/util.py +1 -1
  18. sphinx/builders/linkcheck.py +86 -27
  19. sphinx/builders/manpage.py +8 -6
  20. sphinx/builders/singlehtml.py +5 -4
  21. sphinx/builders/texinfo.py +18 -14
  22. sphinx/builders/text.py +3 -2
  23. sphinx/builders/xml.py +5 -2
  24. sphinx/cmd/build.py +119 -76
  25. sphinx/cmd/make_mode.py +4 -9
  26. sphinx/cmd/quickstart.py +13 -16
  27. sphinx/config.py +432 -250
  28. sphinx/deprecation.py +23 -13
  29. sphinx/directives/__init__.py +8 -8
  30. sphinx/directives/code.py +7 -7
  31. sphinx/directives/other.py +23 -13
  32. sphinx/directives/patches.py +7 -6
  33. sphinx/domains/__init__.py +2 -2
  34. sphinx/domains/c/__init__.py +796 -0
  35. sphinx/domains/c/_ast.py +1421 -0
  36. sphinx/domains/c/_ids.py +65 -0
  37. sphinx/domains/c/_parser.py +1048 -0
  38. sphinx/domains/c/_symbol.py +700 -0
  39. sphinx/domains/changeset.py +11 -7
  40. sphinx/domains/citation.py +5 -2
  41. sphinx/domains/cpp/__init__.py +1089 -0
  42. sphinx/domains/cpp/_ast.py +3635 -0
  43. sphinx/domains/cpp/_ids.py +537 -0
  44. sphinx/domains/cpp/_parser.py +2117 -0
  45. sphinx/domains/cpp/_symbol.py +1092 -0
  46. sphinx/domains/index.py +6 -4
  47. sphinx/domains/javascript.py +16 -13
  48. sphinx/domains/math.py +9 -4
  49. sphinx/domains/python/__init__.py +890 -0
  50. sphinx/domains/python/_annotations.py +507 -0
  51. sphinx/domains/python/_object.py +426 -0
  52. sphinx/domains/rst.py +12 -7
  53. sphinx/domains/{std.py → std/__init__.py} +19 -16
  54. sphinx/environment/__init__.py +21 -19
  55. sphinx/environment/adapters/indexentries.py +2 -2
  56. sphinx/environment/adapters/toctree.py +10 -9
  57. sphinx/environment/collectors/__init__.py +6 -3
  58. sphinx/environment/collectors/asset.py +4 -3
  59. sphinx/environment/collectors/dependencies.py +3 -2
  60. sphinx/environment/collectors/metadata.py +6 -5
  61. sphinx/environment/collectors/title.py +3 -2
  62. sphinx/environment/collectors/toctree.py +5 -4
  63. sphinx/errors.py +13 -2
  64. sphinx/events.py +14 -9
  65. sphinx/ext/apidoc.py +9 -11
  66. sphinx/ext/autodoc/__init__.py +105 -71
  67. sphinx/ext/autodoc/directive.py +7 -6
  68. sphinx/ext/autodoc/importer.py +102 -36
  69. sphinx/ext/autodoc/mock.py +7 -5
  70. sphinx/ext/autodoc/preserve_defaults.py +4 -3
  71. sphinx/ext/autodoc/type_comment.py +2 -1
  72. sphinx/ext/autodoc/typehints.py +5 -4
  73. sphinx/ext/autosectionlabel.py +3 -2
  74. sphinx/ext/autosummary/__init__.py +21 -17
  75. sphinx/ext/autosummary/generate.py +9 -9
  76. sphinx/ext/coverage.py +26 -20
  77. sphinx/ext/doctest.py +38 -33
  78. sphinx/ext/duration.py +1 -0
  79. sphinx/ext/extlinks.py +4 -3
  80. sphinx/ext/githubpages.py +3 -2
  81. sphinx/ext/graphviz.py +10 -7
  82. sphinx/ext/ifconfig.py +5 -5
  83. sphinx/ext/imgconverter.py +6 -5
  84. sphinx/ext/imgmath.py +9 -8
  85. sphinx/ext/inheritance_diagram.py +31 -31
  86. sphinx/ext/intersphinx.py +140 -23
  87. sphinx/ext/linkcode.py +3 -2
  88. sphinx/ext/mathjax.py +2 -1
  89. sphinx/ext/napoleon/__init__.py +12 -7
  90. sphinx/ext/napoleon/docstring.py +34 -32
  91. sphinx/ext/todo.py +10 -7
  92. sphinx/ext/viewcode.py +12 -11
  93. sphinx/extension.py +18 -8
  94. sphinx/highlighting.py +39 -20
  95. sphinx/io.py +17 -8
  96. sphinx/jinja2glue.py +16 -15
  97. sphinx/locale/__init__.py +30 -23
  98. sphinx/locale/ar/LC_MESSAGES/sphinx.mo +0 -0
  99. sphinx/locale/ar/LC_MESSAGES/sphinx.po +818 -761
  100. sphinx/locale/bg/LC_MESSAGES/sphinx.mo +0 -0
  101. sphinx/locale/bg/LC_MESSAGES/sphinx.po +811 -754
  102. sphinx/locale/bn/LC_MESSAGES/sphinx.mo +0 -0
  103. sphinx/locale/bn/LC_MESSAGES/sphinx.po +835 -778
  104. sphinx/locale/ca/LC_MESSAGES/sphinx.mo +0 -0
  105. sphinx/locale/ca/LC_MESSAGES/sphinx.po +864 -807
  106. sphinx/locale/cak/LC_MESSAGES/sphinx.mo +0 -0
  107. sphinx/locale/cak/LC_MESSAGES/sphinx.po +816 -759
  108. sphinx/locale/cs/LC_MESSAGES/sphinx.mo +0 -0
  109. sphinx/locale/cs/LC_MESSAGES/sphinx.po +837 -780
  110. sphinx/locale/cy/LC_MESSAGES/sphinx.mo +0 -0
  111. sphinx/locale/cy/LC_MESSAGES/sphinx.po +819 -762
  112. sphinx/locale/da/LC_MESSAGES/sphinx.mo +0 -0
  113. sphinx/locale/da/LC_MESSAGES/sphinx.po +838 -781
  114. sphinx/locale/de/LC_MESSAGES/sphinx.mo +0 -0
  115. sphinx/locale/de/LC_MESSAGES/sphinx.po +838 -781
  116. sphinx/locale/de_DE/LC_MESSAGES/sphinx.mo +0 -0
  117. sphinx/locale/de_DE/LC_MESSAGES/sphinx.po +811 -754
  118. sphinx/locale/el/LC_MESSAGES/sphinx.mo +0 -0
  119. sphinx/locale/el/LC_MESSAGES/sphinx.po +853 -796
  120. sphinx/locale/en_DE/LC_MESSAGES/sphinx.mo +0 -0
  121. sphinx/locale/en_DE/LC_MESSAGES/sphinx.po +811 -754
  122. sphinx/locale/en_FR/LC_MESSAGES/sphinx.mo +0 -0
  123. sphinx/locale/en_FR/LC_MESSAGES/sphinx.po +811 -754
  124. sphinx/locale/en_GB/LC_MESSAGES/sphinx.mo +0 -0
  125. sphinx/locale/en_GB/LC_MESSAGES/sphinx.po +856 -799
  126. sphinx/locale/en_HK/LC_MESSAGES/sphinx.mo +0 -0
  127. sphinx/locale/en_HK/LC_MESSAGES/sphinx.po +811 -754
  128. sphinx/locale/eo/LC_MESSAGES/sphinx.mo +0 -0
  129. sphinx/locale/eo/LC_MESSAGES/sphinx.po +820 -763
  130. sphinx/locale/es/LC_MESSAGES/sphinx.mo +0 -0
  131. sphinx/locale/es/LC_MESSAGES/sphinx.po +856 -799
  132. sphinx/locale/es_CO/LC_MESSAGES/sphinx.mo +0 -0
  133. sphinx/locale/es_CO/LC_MESSAGES/sphinx.po +811 -754
  134. sphinx/locale/et/LC_MESSAGES/sphinx.mo +0 -0
  135. sphinx/locale/et/LC_MESSAGES/sphinx.po +845 -788
  136. sphinx/locale/eu/LC_MESSAGES/sphinx.mo +0 -0
  137. sphinx/locale/eu/LC_MESSAGES/sphinx.po +837 -780
  138. sphinx/locale/fa/LC_MESSAGES/sphinx.mo +0 -0
  139. sphinx/locale/fa/LC_MESSAGES/sphinx.po +854 -797
  140. sphinx/locale/fi/LC_MESSAGES/sphinx.mo +0 -0
  141. sphinx/locale/fi/LC_MESSAGES/sphinx.po +816 -759
  142. sphinx/locale/fr/LC_MESSAGES/sphinx.js +1 -1
  143. sphinx/locale/fr/LC_MESSAGES/sphinx.mo +0 -0
  144. sphinx/locale/fr/LC_MESSAGES/sphinx.po +904 -847
  145. sphinx/locale/fr_FR/LC_MESSAGES/sphinx.mo +0 -0
  146. sphinx/locale/fr_FR/LC_MESSAGES/sphinx.po +811 -754
  147. sphinx/locale/gl/LC_MESSAGES/sphinx.js +54 -54
  148. sphinx/locale/gl/LC_MESSAGES/sphinx.mo +0 -0
  149. sphinx/locale/gl/LC_MESSAGES/sphinx.po +1506 -1449
  150. sphinx/locale/he/LC_MESSAGES/sphinx.js +1 -1
  151. sphinx/locale/he/LC_MESSAGES/sphinx.mo +0 -0
  152. sphinx/locale/he/LC_MESSAGES/sphinx.po +823 -766
  153. sphinx/locale/hi/LC_MESSAGES/sphinx.mo +0 -0
  154. sphinx/locale/hi/LC_MESSAGES/sphinx.po +853 -796
  155. sphinx/locale/hi_IN/LC_MESSAGES/sphinx.mo +0 -0
  156. sphinx/locale/hi_IN/LC_MESSAGES/sphinx.po +811 -754
  157. sphinx/locale/hr/LC_MESSAGES/sphinx.mo +0 -0
  158. sphinx/locale/hr/LC_MESSAGES/sphinx.po +844 -787
  159. sphinx/locale/hu/LC_MESSAGES/sphinx.mo +0 -0
  160. sphinx/locale/hu/LC_MESSAGES/sphinx.po +837 -780
  161. sphinx/locale/id/LC_MESSAGES/sphinx.mo +0 -0
  162. sphinx/locale/id/LC_MESSAGES/sphinx.po +854 -797
  163. sphinx/locale/is/LC_MESSAGES/sphinx.mo +0 -0
  164. sphinx/locale/is/LC_MESSAGES/sphinx.po +811 -754
  165. sphinx/locale/it/LC_MESSAGES/sphinx.mo +0 -0
  166. sphinx/locale/it/LC_MESSAGES/sphinx.po +837 -780
  167. sphinx/locale/ja/LC_MESSAGES/sphinx.mo +0 -0
  168. sphinx/locale/ja/LC_MESSAGES/sphinx.po +853 -796
  169. sphinx/locale/ka/LC_MESSAGES/sphinx.mo +0 -0
  170. sphinx/locale/ka/LC_MESSAGES/sphinx.po +848 -791
  171. sphinx/locale/ko/LC_MESSAGES/sphinx.mo +0 -0
  172. sphinx/locale/ko/LC_MESSAGES/sphinx.po +855 -798
  173. sphinx/locale/lt/LC_MESSAGES/sphinx.mo +0 -0
  174. sphinx/locale/lt/LC_MESSAGES/sphinx.po +837 -780
  175. sphinx/locale/lv/LC_MESSAGES/sphinx.mo +0 -0
  176. sphinx/locale/lv/LC_MESSAGES/sphinx.po +837 -780
  177. sphinx/locale/mk/LC_MESSAGES/sphinx.mo +0 -0
  178. sphinx/locale/mk/LC_MESSAGES/sphinx.po +825 -768
  179. sphinx/locale/nb_NO/LC_MESSAGES/sphinx.js +27 -27
  180. sphinx/locale/nb_NO/LC_MESSAGES/sphinx.mo +0 -0
  181. sphinx/locale/nb_NO/LC_MESSAGES/sphinx.po +876 -818
  182. sphinx/locale/ne/LC_MESSAGES/sphinx.mo +0 -0
  183. sphinx/locale/ne/LC_MESSAGES/sphinx.po +837 -780
  184. sphinx/locale/nl/LC_MESSAGES/sphinx.mo +0 -0
  185. sphinx/locale/nl/LC_MESSAGES/sphinx.po +844 -787
  186. sphinx/locale/pl/LC_MESSAGES/sphinx.mo +0 -0
  187. sphinx/locale/pl/LC_MESSAGES/sphinx.po +845 -788
  188. sphinx/locale/pt/LC_MESSAGES/sphinx.mo +0 -0
  189. sphinx/locale/pt/LC_MESSAGES/sphinx.po +811 -754
  190. sphinx/locale/pt_BR/LC_MESSAGES/sphinx.mo +0 -0
  191. sphinx/locale/pt_BR/LC_MESSAGES/sphinx.po +908 -851
  192. sphinx/locale/pt_PT/LC_MESSAGES/sphinx.mo +0 -0
  193. sphinx/locale/pt_PT/LC_MESSAGES/sphinx.po +837 -780
  194. sphinx/locale/ro/LC_MESSAGES/sphinx.mo +0 -0
  195. sphinx/locale/ro/LC_MESSAGES/sphinx.po +837 -780
  196. sphinx/locale/ru/LC_MESSAGES/sphinx.mo +0 -0
  197. sphinx/locale/ru/LC_MESSAGES/sphinx.po +838 -781
  198. sphinx/locale/si/LC_MESSAGES/sphinx.mo +0 -0
  199. sphinx/locale/si/LC_MESSAGES/sphinx.po +823 -766
  200. sphinx/locale/sk/LC_MESSAGES/sphinx.mo +0 -0
  201. sphinx/locale/sk/LC_MESSAGES/sphinx.po +854 -797
  202. sphinx/locale/sl/LC_MESSAGES/sphinx.mo +0 -0
  203. sphinx/locale/sl/LC_MESSAGES/sphinx.po +832 -775
  204. sphinx/locale/sphinx.pot +813 -755
  205. sphinx/locale/sq/LC_MESSAGES/sphinx.js +1 -1
  206. sphinx/locale/sq/LC_MESSAGES/sphinx.mo +0 -0
  207. sphinx/locale/sq/LC_MESSAGES/sphinx.po +865 -808
  208. sphinx/locale/sr/LC_MESSAGES/sphinx.mo +0 -0
  209. sphinx/locale/sr/LC_MESSAGES/sphinx.po +835 -778
  210. sphinx/locale/sr@latin/LC_MESSAGES/sphinx.mo +0 -0
  211. sphinx/locale/sr_RS/LC_MESSAGES/sphinx.mo +0 -0
  212. sphinx/locale/sv/LC_MESSAGES/sphinx.mo +0 -0
  213. sphinx/locale/sv/LC_MESSAGES/sphinx.po +837 -780
  214. sphinx/locale/ta/LC_MESSAGES/sphinx.js +54 -54
  215. sphinx/locale/ta/LC_MESSAGES/sphinx.mo +0 -0
  216. sphinx/locale/ta/LC_MESSAGES/sphinx.po +1530 -1473
  217. sphinx/locale/te/LC_MESSAGES/sphinx.mo +0 -0
  218. sphinx/locale/te/LC_MESSAGES/sphinx.po +811 -754
  219. sphinx/locale/tr/LC_MESSAGES/sphinx.mo +0 -0
  220. sphinx/locale/tr/LC_MESSAGES/sphinx.po +853 -796
  221. sphinx/locale/uk_UA/LC_MESSAGES/sphinx.mo +0 -0
  222. sphinx/locale/uk_UA/LC_MESSAGES/sphinx.po +833 -776
  223. sphinx/locale/ur/LC_MESSAGES/sphinx.mo +0 -0
  224. sphinx/locale/ur/LC_MESSAGES/sphinx.po +811 -754
  225. sphinx/locale/vi/LC_MESSAGES/sphinx.mo +0 -0
  226. sphinx/locale/vi/LC_MESSAGES/sphinx.po +837 -780
  227. sphinx/locale/yue/LC_MESSAGES/sphinx.mo +0 -0
  228. sphinx/locale/yue/LC_MESSAGES/sphinx.po +811 -754
  229. sphinx/locale/zh_CN/LC_MESSAGES/sphinx.mo +0 -0
  230. sphinx/locale/zh_CN/LC_MESSAGES/sphinx.po +855 -798
  231. sphinx/locale/zh_HK/LC_MESSAGES/sphinx.mo +0 -0
  232. sphinx/locale/zh_HK/LC_MESSAGES/sphinx.po +811 -754
  233. sphinx/locale/zh_TW/LC_MESSAGES/sphinx.js +1 -1
  234. sphinx/locale/zh_TW/LC_MESSAGES/sphinx.mo +0 -0
  235. sphinx/locale/zh_TW/LC_MESSAGES/sphinx.po +879 -822
  236. sphinx/locale/zh_TW.Big5/LC_MESSAGES/sphinx.mo +0 -0
  237. sphinx/locale/zh_TW.Big5/LC_MESSAGES/sphinx.po +811 -754
  238. sphinx/parsers.py +7 -5
  239. sphinx/project.py +18 -11
  240. sphinx/pycode/__init__.py +6 -5
  241. sphinx/pycode/ast.py +23 -8
  242. sphinx/pycode/parser.py +6 -5
  243. sphinx/registry.py +12 -6
  244. sphinx/roles.py +103 -57
  245. sphinx/search/__init__.py +17 -18
  246. sphinx/search/da.py +2 -2
  247. sphinx/search/de.py +2 -2
  248. sphinx/search/en.py +1 -1
  249. sphinx/search/es.py +2 -2
  250. sphinx/search/fi.py +2 -2
  251. sphinx/search/fr.py +2 -2
  252. sphinx/search/hu.py +2 -2
  253. sphinx/search/it.py +2 -2
  254. sphinx/search/ja.py +13 -22
  255. sphinx/search/nl.py +2 -2
  256. sphinx/search/no.py +2 -2
  257. sphinx/search/pt.py +2 -2
  258. sphinx/search/ro.py +1 -1
  259. sphinx/search/ru.py +2 -2
  260. sphinx/search/sv.py +2 -2
  261. sphinx/search/tr.py +1 -1
  262. sphinx/search/zh.py +2 -3
  263. sphinx/templates/graphviz/graphviz.css +1 -1
  264. sphinx/testing/fixtures.py +41 -24
  265. sphinx/testing/path.py +1 -1
  266. sphinx/testing/util.py +142 -53
  267. sphinx/texinputs/sphinx.xdy +1 -1
  268. sphinx/texinputs/sphinxlatextables.sty +1 -1
  269. sphinx/texinputs/sphinxpackagesubstitutefont.sty +21 -0
  270. sphinx/themes/agogo/layout.html +4 -4
  271. sphinx/themes/agogo/static/agogo.css_t +1 -1
  272. sphinx/themes/agogo/theme.toml +22 -0
  273. sphinx/themes/basic/defindex.html +1 -1
  274. sphinx/themes/basic/domainindex.html +1 -1
  275. sphinx/themes/basic/genindex-single.html +1 -1
  276. sphinx/themes/basic/genindex-split.html +1 -1
  277. sphinx/themes/basic/genindex.html +1 -1
  278. sphinx/themes/basic/globaltoc.html +1 -1
  279. sphinx/themes/basic/layout.html +1 -1
  280. sphinx/themes/basic/localtoc.html +1 -1
  281. sphinx/themes/basic/page.html +1 -1
  282. sphinx/themes/basic/relations.html +1 -1
  283. sphinx/themes/basic/search.html +5 -20
  284. sphinx/themes/basic/searchbox.html +3 -3
  285. sphinx/themes/basic/searchfield.html +3 -3
  286. sphinx/themes/basic/sourcelink.html +1 -1
  287. sphinx/themes/basic/static/basic.css_t +1 -1
  288. sphinx/themes/basic/static/doctools.js +1 -1
  289. sphinx/themes/basic/static/language_data.js_t +2 -2
  290. sphinx/themes/basic/static/searchtools.js +105 -60
  291. sphinx/themes/basic/theme.toml +23 -0
  292. sphinx/themes/bizstyle/layout.html +1 -6
  293. sphinx/themes/bizstyle/static/bizstyle.css_t +1 -1
  294. sphinx/themes/bizstyle/static/bizstyle.js_t +1 -1
  295. sphinx/themes/bizstyle/static/css3-mediaqueries_src.js +3 -3
  296. sphinx/themes/bizstyle/theme.toml +12 -0
  297. sphinx/themes/classic/layout.html +1 -1
  298. sphinx/themes/classic/static/classic.css_t +1 -1
  299. sphinx/themes/classic/static/sidebar.js_t +1 -1
  300. sphinx/themes/classic/theme.toml +34 -0
  301. sphinx/themes/default/theme.toml +2 -0
  302. sphinx/themes/epub/epub-cover.html +1 -1
  303. sphinx/themes/epub/layout.html +1 -1
  304. sphinx/themes/epub/static/epub.css_t +1 -1
  305. sphinx/themes/epub/theme.toml +10 -0
  306. sphinx/themes/haiku/layout.html +3 -3
  307. sphinx/themes/haiku/static/haiku.css_t +2 -2
  308. sphinx/themes/haiku/theme.toml +16 -0
  309. sphinx/themes/nature/static/nature.css_t +1 -1
  310. sphinx/themes/nature/theme.toml +6 -0
  311. sphinx/themes/nonav/layout.html +1 -1
  312. sphinx/themes/nonav/static/nonav.css_t +1 -1
  313. sphinx/themes/nonav/theme.toml +10 -0
  314. sphinx/themes/pyramid/static/epub.css_t +1 -1
  315. sphinx/themes/pyramid/static/pyramid.css_t +1 -1
  316. sphinx/themes/pyramid/theme.toml +6 -0
  317. sphinx/themes/scrolls/artwork/logo.svg +1 -1
  318. sphinx/themes/scrolls/layout.html +2 -2
  319. sphinx/themes/scrolls/static/scrolls.css_t +1 -1
  320. sphinx/themes/scrolls/theme.toml +15 -0
  321. sphinx/themes/sphinxdoc/static/sphinxdoc.css_t +1 -1
  322. sphinx/themes/sphinxdoc/theme.toml +6 -0
  323. sphinx/themes/traditional/static/traditional.css_t +1 -1
  324. sphinx/themes/traditional/theme.toml +9 -0
  325. sphinx/theming.py +427 -131
  326. sphinx/transforms/__init__.py +21 -24
  327. sphinx/transforms/compact_bullet_list.py +5 -5
  328. sphinx/transforms/i18n.py +30 -28
  329. sphinx/transforms/post_transforms/__init__.py +9 -7
  330. sphinx/transforms/post_transforms/code.py +4 -1
  331. sphinx/transforms/post_transforms/images.py +17 -13
  332. sphinx/transforms/references.py +3 -1
  333. sphinx/util/__init__.py +15 -11
  334. sphinx/util/_io.py +34 -0
  335. sphinx/util/_pathlib.py +23 -18
  336. sphinx/util/build_phase.py +1 -0
  337. sphinx/util/cfamily.py +19 -11
  338. sphinx/util/console.py +101 -21
  339. sphinx/util/display.py +3 -2
  340. sphinx/util/docfields.py +12 -8
  341. sphinx/util/docutils.py +21 -35
  342. sphinx/util/exceptions.py +3 -2
  343. sphinx/util/fileutil.py +5 -5
  344. sphinx/util/http_date.py +9 -2
  345. sphinx/util/i18n.py +40 -9
  346. sphinx/util/inspect.py +317 -245
  347. sphinx/util/inventory.py +22 -5
  348. sphinx/util/logging.py +81 -7
  349. sphinx/util/matching.py +2 -1
  350. sphinx/util/math.py +1 -2
  351. sphinx/util/nodes.py +39 -29
  352. sphinx/util/osutil.py +25 -6
  353. sphinx/util/parallel.py +6 -1
  354. sphinx/util/requests.py +8 -5
  355. sphinx/util/rst.py +8 -6
  356. sphinx/util/tags.py +3 -3
  357. sphinx/util/template.py +8 -3
  358. sphinx/util/typing.py +76 -42
  359. sphinx/versioning.py +6 -2
  360. sphinx/writers/html.py +1 -1
  361. sphinx/writers/html5.py +17 -13
  362. sphinx/writers/latex.py +12 -12
  363. sphinx/writers/manpage.py +13 -7
  364. sphinx/writers/texinfo.py +13 -10
  365. sphinx/writers/text.py +13 -23
  366. sphinx/writers/xml.py +1 -1
  367. sphinx-7.2.6.dist-info/LICENSE → sphinx-7.3.0.dist-info/LICENSE.rst +1 -1
  368. {sphinx-7.2.6.dist-info → sphinx-7.3.0.dist-info}/METADATA +13 -12
  369. sphinx-7.3.0.dist-info/RECORD +581 -0
  370. sphinx/domains/c.py +0 -3906
  371. sphinx/domains/cpp.py +0 -8233
  372. sphinx/domains/python.py +0 -1769
  373. sphinx/themes/agogo/theme.conf +0 -20
  374. sphinx/themes/basic/theme.conf +0 -16
  375. sphinx/themes/bizstyle/theme.conf +0 -10
  376. sphinx/themes/classic/theme.conf +0 -32
  377. sphinx/themes/default/theme.conf +0 -2
  378. sphinx/themes/epub/theme.conf +0 -8
  379. sphinx/themes/haiku/theme.conf +0 -14
  380. sphinx/themes/nature/theme.conf +0 -4
  381. sphinx/themes/nonav/theme.conf +0 -8
  382. sphinx/themes/pyramid/theme.conf +0 -4
  383. sphinx/themes/scrolls/theme.conf +0 -13
  384. sphinx/themes/sphinxdoc/theme.conf +0 -4
  385. sphinx/themes/traditional/theme.conf +0 -7
  386. sphinx-7.2.6.dist-info/RECORD +0 -569
  387. {sphinx-7.2.6.dist-info → sphinx-7.3.0.dist-info}/WHEEL +0 -0
  388. {sphinx-7.2.6.dist-info → sphinx-7.3.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,3635 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any
4
+
5
+ from docutils import nodes
6
+
7
+ from sphinx import addnodes
8
+ from sphinx.domains.cpp._ids import (
9
+ _id_char_from_prefix,
10
+ _id_explicit_cast,
11
+ _id_fundamental_v1,
12
+ _id_fundamental_v2,
13
+ _id_operator_unary_v2,
14
+ _id_operator_v1,
15
+ _id_operator_v2,
16
+ _id_prefix,
17
+ _id_shorthands_v1,
18
+ _max_id,
19
+ )
20
+ from sphinx.util.cfamily import (
21
+ ASTAttributeList,
22
+ ASTBaseBase,
23
+ ASTBaseParenExprList,
24
+ NoOldIdError,
25
+ StringifyTransform,
26
+ UnsupportedMultiCharacterCharLiteral,
27
+ verify_description_mode,
28
+ )
29
+
30
+ if TYPE_CHECKING:
31
+
32
+ from docutils.nodes import Element, TextElement
33
+
34
+ from sphinx.addnodes import desc_signature
35
+ from sphinx.domains.cpp._symbol import Symbol
36
+ from sphinx.environment import BuildEnvironment
37
+
38
+
39
+ class ASTBase(ASTBaseBase):
40
+ pass
41
+
42
+
43
+ # Names
44
+ ################################################################################
45
+
46
+ class ASTIdentifier(ASTBase):
47
+ def __init__(self, identifier: str) -> None:
48
+ assert identifier is not None
49
+ assert len(identifier) != 0
50
+ self.identifier = identifier
51
+
52
+ # ASTBaseBase already implements this method,
53
+ # but specialising it here improves performance
54
+ def __eq__(self, other: object) -> bool:
55
+ if type(other) is not ASTIdentifier:
56
+ return NotImplemented
57
+ return self.identifier == other.identifier
58
+
59
+ def _stringify(self, transform: StringifyTransform) -> str:
60
+ return transform(self.identifier)
61
+
62
+ def is_anon(self) -> bool:
63
+ return self.identifier[0] == '@'
64
+
65
+ def get_id(self, version: int) -> str:
66
+ if self.is_anon() and version < 3:
67
+ raise NoOldIdError
68
+ if version == 1:
69
+ if self.identifier == 'size_t':
70
+ return 's'
71
+ else:
72
+ return self.identifier
73
+ if self.identifier == "std":
74
+ return 'St'
75
+ elif self.identifier[0] == "~":
76
+ # a destructor, just use an arbitrary version of dtors
77
+ return 'D0'
78
+ else:
79
+ if self.is_anon():
80
+ return 'Ut%d_%s' % (len(self.identifier) - 1, self.identifier[1:])
81
+ else:
82
+ return str(len(self.identifier)) + self.identifier
83
+
84
+ # and this is where we finally make a difference between __str__ and the display string
85
+
86
+ def __str__(self) -> str:
87
+ return self.identifier
88
+
89
+ def get_display_string(self) -> str:
90
+ return "[anonymous]" if self.is_anon() else self.identifier
91
+
92
+ def describe_signature(self, signode: TextElement, mode: str, env: BuildEnvironment,
93
+ prefix: str, templateArgs: str, symbol: Symbol) -> None:
94
+ verify_description_mode(mode)
95
+ if self.is_anon():
96
+ node = addnodes.desc_sig_name(text="[anonymous]")
97
+ else:
98
+ node = addnodes.desc_sig_name(self.identifier, self.identifier)
99
+ if mode == 'markType':
100
+ targetText = prefix + self.identifier + templateArgs
101
+ pnode = addnodes.pending_xref('', refdomain='cpp',
102
+ reftype='identifier',
103
+ reftarget=targetText, modname=None,
104
+ classname=None)
105
+ pnode['cpp:parent_key'] = symbol.get_lookup_key()
106
+ pnode += node
107
+ signode += pnode
108
+ elif mode == 'lastIsName':
109
+ nameNode = addnodes.desc_name()
110
+ nameNode += node
111
+ signode += nameNode
112
+ elif mode == 'noneIsName':
113
+ signode += node
114
+ elif mode == 'param':
115
+ node['classes'].append('sig-param')
116
+ signode += node
117
+ elif mode == 'udl':
118
+ # the target is 'operator""id' instead of just 'id'
119
+ assert len(prefix) == 0
120
+ assert len(templateArgs) == 0
121
+ assert not self.is_anon()
122
+ targetText = 'operator""' + self.identifier
123
+ pnode = addnodes.pending_xref('', refdomain='cpp',
124
+ reftype='identifier',
125
+ reftarget=targetText, modname=None,
126
+ classname=None)
127
+ pnode['cpp:parent_key'] = symbol.get_lookup_key()
128
+ pnode += node
129
+ signode += pnode
130
+ else:
131
+ raise Exception('Unknown description mode: %s' % mode)
132
+
133
+
134
+ class ASTNestedNameElement(ASTBase):
135
+ def __init__(self, identOrOp: ASTIdentifier | ASTOperator,
136
+ templateArgs: ASTTemplateArgs | None) -> None:
137
+ self.identOrOp = identOrOp
138
+ self.templateArgs = templateArgs
139
+
140
+ def is_operator(self) -> bool:
141
+ return False
142
+
143
+ def get_id(self, version: int) -> str:
144
+ res = self.identOrOp.get_id(version)
145
+ if self.templateArgs:
146
+ res += self.templateArgs.get_id(version)
147
+ return res
148
+
149
+ def _stringify(self, transform: StringifyTransform) -> str:
150
+ res = transform(self.identOrOp)
151
+ if self.templateArgs:
152
+ res += transform(self.templateArgs)
153
+ return res
154
+
155
+ def describe_signature(self, signode: TextElement, mode: str,
156
+ env: BuildEnvironment, prefix: str, symbol: Symbol) -> None:
157
+ tArgs = str(self.templateArgs) if self.templateArgs is not None else ''
158
+ self.identOrOp.describe_signature(signode, mode, env, prefix, tArgs, symbol)
159
+ if self.templateArgs is not None:
160
+ self.templateArgs.describe_signature(signode, 'markType', env, symbol)
161
+
162
+
163
+ class ASTNestedName(ASTBase):
164
+ def __init__(self, names: list[ASTNestedNameElement],
165
+ templates: list[bool], rooted: bool) -> None:
166
+ assert len(names) > 0
167
+ self.names = names
168
+ self.templates = templates
169
+ assert len(self.names) == len(self.templates)
170
+ self.rooted = rooted
171
+
172
+ @property
173
+ def name(self) -> ASTNestedName:
174
+ return self
175
+
176
+ def num_templates(self) -> int:
177
+ count = 0
178
+ for n in self.names:
179
+ if n.is_operator():
180
+ continue
181
+ if n.templateArgs:
182
+ count += 1
183
+ return count
184
+
185
+ def get_id(self, version: int, modifiers: str = '') -> str:
186
+ if version == 1:
187
+ tt = str(self)
188
+ if tt in _id_shorthands_v1:
189
+ return _id_shorthands_v1[tt]
190
+ else:
191
+ return '::'.join(n.get_id(version) for n in self.names)
192
+
193
+ res = []
194
+ if len(self.names) > 1 or len(modifiers) > 0:
195
+ res.append('N')
196
+ res.append(modifiers)
197
+ res.extend(n.get_id(version) for n in self.names)
198
+ if len(self.names) > 1 or len(modifiers) > 0:
199
+ res.append('E')
200
+ return ''.join(res)
201
+
202
+ def _stringify(self, transform: StringifyTransform) -> str:
203
+ res = []
204
+ if self.rooted:
205
+ res.append('')
206
+ for i in range(len(self.names)):
207
+ n = self.names[i]
208
+ if self.templates[i]:
209
+ res.append("template " + transform(n))
210
+ else:
211
+ res.append(transform(n))
212
+ return '::'.join(res)
213
+
214
+ def describe_signature(self, signode: TextElement, mode: str,
215
+ env: BuildEnvironment, symbol: Symbol) -> None:
216
+ verify_description_mode(mode)
217
+ # just print the name part, with template args, not template params
218
+ if mode == 'noneIsName':
219
+ if self.rooted:
220
+ unreachable = "Can this happen?"
221
+ raise AssertionError(unreachable) # TODO
222
+ signode += nodes.Text('::')
223
+ for i in range(len(self.names)):
224
+ if i != 0:
225
+ unreachable = "Can this happen?"
226
+ raise AssertionError(unreachable) # TODO
227
+ signode += nodes.Text('::blah')
228
+ n = self.names[i]
229
+ if self.templates[i]:
230
+ unreachable = "Can this happen?"
231
+ raise AssertionError(unreachable) # TODO
232
+ signode += nodes.Text("template")
233
+ signode += nodes.Text(" ")
234
+ n.describe_signature(signode, mode, env, '', symbol)
235
+ elif mode == 'param':
236
+ assert not self.rooted, str(self)
237
+ assert len(self.names) == 1
238
+ assert not self.templates[0]
239
+ self.names[0].describe_signature(signode, 'param', env, '', symbol)
240
+ elif mode in ('markType', 'lastIsName', 'markName'):
241
+ # Each element should be a pending xref targeting the complete
242
+ # prefix. however, only the identifier part should be a link, such
243
+ # that template args can be a link as well.
244
+ # For 'lastIsName' we should also prepend template parameter lists.
245
+ templateParams: list[Any] = []
246
+ if mode == 'lastIsName':
247
+ assert symbol is not None
248
+ if symbol.declaration.templatePrefix is not None:
249
+ templateParams = symbol.declaration.templatePrefix.templates
250
+ iTemplateParams = 0
251
+ templateParamsPrefix = ''
252
+ prefix = ''
253
+ first = True
254
+ names = self.names[:-1] if mode == 'lastIsName' else self.names
255
+ # If lastIsName, then wrap all of the prefix in a desc_addname,
256
+ # else append directly to signode.
257
+ # NOTE: Breathe previously relied on the prefix being in the desc_addname node,
258
+ # so it can remove it in inner declarations.
259
+ dest = signode
260
+ if mode == 'lastIsName':
261
+ dest = addnodes.desc_addname()
262
+ if self.rooted:
263
+ prefix += '::'
264
+ if mode == 'lastIsName' and len(names) == 0:
265
+ signode += addnodes.desc_sig_punctuation('::', '::')
266
+ else:
267
+ dest += addnodes.desc_sig_punctuation('::', '::')
268
+ for i in range(len(names)):
269
+ nne = names[i]
270
+ template = self.templates[i]
271
+ if not first:
272
+ dest += addnodes.desc_sig_punctuation('::', '::')
273
+ prefix += '::'
274
+ if template:
275
+ dest += addnodes.desc_sig_keyword('template', 'template')
276
+ dest += addnodes.desc_sig_space()
277
+ first = False
278
+ txt_nne = str(nne)
279
+ if txt_nne != '':
280
+ if nne.templateArgs and iTemplateParams < len(templateParams):
281
+ templateParamsPrefix += str(templateParams[iTemplateParams])
282
+ iTemplateParams += 1
283
+ nne.describe_signature(dest, 'markType',
284
+ env, templateParamsPrefix + prefix, symbol)
285
+ prefix += txt_nne
286
+ if mode == 'lastIsName':
287
+ if len(self.names) > 1:
288
+ dest += addnodes.desc_sig_punctuation('::', '::')
289
+ signode += dest
290
+ if self.templates[-1]:
291
+ signode += addnodes.desc_sig_keyword('template', 'template')
292
+ signode += addnodes.desc_sig_space()
293
+ self.names[-1].describe_signature(signode, mode, env, '', symbol)
294
+ else:
295
+ raise Exception('Unknown description mode: %s' % mode)
296
+
297
+
298
+ ################################################################################
299
+ # Expressions
300
+ ################################################################################
301
+
302
+ class ASTExpression(ASTBase):
303
+ def get_id(self, version: int) -> str:
304
+ raise NotImplementedError(repr(self))
305
+
306
+ def describe_signature(self, signode: TextElement, mode: str,
307
+ env: BuildEnvironment, symbol: Symbol) -> None:
308
+ raise NotImplementedError(repr(self))
309
+
310
+
311
+ # Primary expressions
312
+ ################################################################################
313
+
314
+ class ASTLiteral(ASTExpression):
315
+ pass
316
+
317
+
318
+ class ASTPointerLiteral(ASTLiteral):
319
+ def _stringify(self, transform: StringifyTransform) -> str:
320
+ return 'nullptr'
321
+
322
+ def get_id(self, version: int) -> str:
323
+ return 'LDnE'
324
+
325
+ def describe_signature(self, signode: TextElement, mode: str,
326
+ env: BuildEnvironment, symbol: Symbol) -> None:
327
+ signode += addnodes.desc_sig_keyword('nullptr', 'nullptr')
328
+
329
+
330
+ class ASTBooleanLiteral(ASTLiteral):
331
+ def __init__(self, value: bool) -> None:
332
+ self.value = value
333
+
334
+ def _stringify(self, transform: StringifyTransform) -> str:
335
+ if self.value:
336
+ return 'true'
337
+ else:
338
+ return 'false'
339
+
340
+ def get_id(self, version: int) -> str:
341
+ if self.value:
342
+ return 'L1E'
343
+ else:
344
+ return 'L0E'
345
+
346
+ def describe_signature(self, signode: TextElement, mode: str,
347
+ env: BuildEnvironment, symbol: Symbol) -> None:
348
+ signode += addnodes.desc_sig_keyword(str(self), str(self))
349
+
350
+
351
+ class ASTNumberLiteral(ASTLiteral):
352
+ def __init__(self, data: str) -> None:
353
+ self.data = data
354
+
355
+ def _stringify(self, transform: StringifyTransform) -> str:
356
+ return self.data
357
+
358
+ def get_id(self, version: int) -> str:
359
+ # TODO: floats should be mangled by writing the hex of the binary representation
360
+ return "L%sE" % self.data.replace("'", "")
361
+
362
+ def describe_signature(self, signode: TextElement, mode: str,
363
+ env: BuildEnvironment, symbol: Symbol) -> None:
364
+ signode += addnodes.desc_sig_literal_number(self.data, self.data)
365
+
366
+
367
+ class ASTStringLiteral(ASTLiteral):
368
+ def __init__(self, data: str) -> None:
369
+ self.data = data
370
+
371
+ def _stringify(self, transform: StringifyTransform) -> str:
372
+ return self.data
373
+
374
+ def get_id(self, version: int) -> str:
375
+ # note: the length is not really correct with escaping
376
+ return "LA%d_KcE" % (len(self.data) - 2)
377
+
378
+ def describe_signature(self, signode: TextElement, mode: str,
379
+ env: BuildEnvironment, symbol: Symbol) -> None:
380
+ signode += addnodes.desc_sig_literal_string(self.data, self.data)
381
+
382
+
383
+ class ASTCharLiteral(ASTLiteral):
384
+ def __init__(self, prefix: str, data: str) -> None:
385
+ self.prefix = prefix # may be None when no prefix
386
+ self.data = data
387
+ assert prefix in _id_char_from_prefix
388
+ self.type = _id_char_from_prefix[prefix]
389
+ decoded = data.encode().decode('unicode-escape')
390
+ if len(decoded) == 1:
391
+ self.value = ord(decoded)
392
+ else:
393
+ raise UnsupportedMultiCharacterCharLiteral(decoded)
394
+
395
+ def _stringify(self, transform: StringifyTransform) -> str:
396
+ if self.prefix is None:
397
+ return "'" + self.data + "'"
398
+ else:
399
+ return self.prefix + "'" + self.data + "'"
400
+
401
+ def get_id(self, version: int) -> str:
402
+ # TODO: the ID should be have L E around it
403
+ return self.type + str(self.value)
404
+
405
+ def describe_signature(self, signode: TextElement, mode: str,
406
+ env: BuildEnvironment, symbol: Symbol) -> None:
407
+ if self.prefix is not None:
408
+ signode += addnodes.desc_sig_keyword(self.prefix, self.prefix)
409
+ txt = "'" + self.data + "'"
410
+ signode += addnodes.desc_sig_literal_char(txt, txt)
411
+
412
+
413
+ class ASTUserDefinedLiteral(ASTLiteral):
414
+ def __init__(self, literal: ASTLiteral, ident: ASTIdentifier) -> None:
415
+ self.literal = literal
416
+ self.ident = ident
417
+
418
+ def _stringify(self, transform: StringifyTransform) -> str:
419
+ return transform(self.literal) + transform(self.ident)
420
+
421
+ def get_id(self, version: int) -> str:
422
+ # mangle as if it was a function call: ident(literal)
423
+ return f'clL_Zli{self.ident.get_id(version)}E{self.literal.get_id(version)}E'
424
+
425
+ def describe_signature(self, signode: TextElement, mode: str,
426
+ env: BuildEnvironment, symbol: Symbol) -> None:
427
+ self.literal.describe_signature(signode, mode, env, symbol)
428
+ self.ident.describe_signature(signode, "udl", env, "", "", symbol)
429
+
430
+
431
+ ################################################################################
432
+
433
+ class ASTThisLiteral(ASTExpression):
434
+ def _stringify(self, transform: StringifyTransform) -> str:
435
+ return "this"
436
+
437
+ def get_id(self, version: int) -> str:
438
+ return "fpT"
439
+
440
+ def describe_signature(self, signode: TextElement, mode: str,
441
+ env: BuildEnvironment, symbol: Symbol) -> None:
442
+ signode += addnodes.desc_sig_keyword('this', 'this')
443
+
444
+
445
+ class ASTFoldExpr(ASTExpression):
446
+ def __init__(self, leftExpr: ASTExpression | None,
447
+ op: str, rightExpr: ASTExpression | None) -> None:
448
+ assert leftExpr is not None or rightExpr is not None
449
+ self.leftExpr = leftExpr
450
+ self.op = op
451
+ self.rightExpr = rightExpr
452
+
453
+ def _stringify(self, transform: StringifyTransform) -> str:
454
+ res = ['(']
455
+ if self.leftExpr:
456
+ res.append(transform(self.leftExpr))
457
+ res.append(' ')
458
+ res.append(self.op)
459
+ res.append(' ')
460
+ res.append('...')
461
+ if self.rightExpr:
462
+ res.append(' ')
463
+ res.append(self.op)
464
+ res.append(' ')
465
+ res.append(transform(self.rightExpr))
466
+ res.append(')')
467
+ return ''.join(res)
468
+
469
+ def get_id(self, version: int) -> str:
470
+ assert version >= 3
471
+ if version == 3:
472
+ return str(self)
473
+ # https://github.com/itanium-cxx-abi/cxx-abi/pull/67
474
+ res = []
475
+ if self.leftExpr is None: # (... op expr)
476
+ res.append('fl')
477
+ elif self.rightExpr is None: # (expr op ...)
478
+ res.append('fr')
479
+ else: # (expr op ... op expr)
480
+ # we don't check where the parameter pack is,
481
+ # we just always call this a binary left fold
482
+ res.append('fL')
483
+ res.append(_id_operator_v2[self.op])
484
+ if self.leftExpr:
485
+ res.append(self.leftExpr.get_id(version))
486
+ if self.rightExpr:
487
+ res.append(self.rightExpr.get_id(version))
488
+ return ''.join(res)
489
+
490
+ def describe_signature(self, signode: TextElement, mode: str,
491
+ env: BuildEnvironment, symbol: Symbol) -> None:
492
+ signode += addnodes.desc_sig_punctuation('(', '(')
493
+ if self.leftExpr:
494
+ self.leftExpr.describe_signature(signode, mode, env, symbol)
495
+ signode += addnodes.desc_sig_space()
496
+ signode += addnodes.desc_sig_operator(self.op, self.op)
497
+ signode += addnodes.desc_sig_space()
498
+ signode += addnodes.desc_sig_punctuation('...', '...')
499
+ if self.rightExpr:
500
+ signode += addnodes.desc_sig_space()
501
+ signode += addnodes.desc_sig_operator(self.op, self.op)
502
+ signode += addnodes.desc_sig_space()
503
+ self.rightExpr.describe_signature(signode, mode, env, symbol)
504
+ signode += addnodes.desc_sig_punctuation(')', ')')
505
+
506
+
507
+ class ASTParenExpr(ASTExpression):
508
+ def __init__(self, expr: ASTExpression) -> None:
509
+ self.expr = expr
510
+
511
+ def _stringify(self, transform: StringifyTransform) -> str:
512
+ return '(' + transform(self.expr) + ')'
513
+
514
+ def get_id(self, version: int) -> str:
515
+ return self.expr.get_id(version)
516
+
517
+ def describe_signature(self, signode: TextElement, mode: str,
518
+ env: BuildEnvironment, symbol: Symbol) -> None:
519
+ signode += addnodes.desc_sig_punctuation('(', '(')
520
+ self.expr.describe_signature(signode, mode, env, symbol)
521
+ signode += addnodes.desc_sig_punctuation(')', ')')
522
+
523
+
524
+ class ASTIdExpression(ASTExpression):
525
+ def __init__(self, name: ASTNestedName) -> None:
526
+ # note: this class is basically to cast a nested name as an expression
527
+ self.name = name
528
+
529
+ def _stringify(self, transform: StringifyTransform) -> str:
530
+ return transform(self.name)
531
+
532
+ def get_id(self, version: int) -> str:
533
+ return self.name.get_id(version)
534
+
535
+ def describe_signature(self, signode: TextElement, mode: str,
536
+ env: BuildEnvironment, symbol: Symbol) -> None:
537
+ self.name.describe_signature(signode, mode, env, symbol)
538
+
539
+
540
+ # Postfix expressions
541
+ ################################################################################
542
+
543
+ class ASTPostfixOp(ASTBase):
544
+ def get_id(self, idPrefix: str, version: int) -> str:
545
+ raise NotImplementedError(repr(self))
546
+
547
+ def describe_signature(self, signode: TextElement, mode: str,
548
+ env: BuildEnvironment, symbol: Symbol) -> None:
549
+ raise NotImplementedError(repr(self))
550
+
551
+
552
+ class ASTPostfixArray(ASTPostfixOp):
553
+ def __init__(self, expr: ASTExpression) -> None:
554
+ self.expr = expr
555
+
556
+ def _stringify(self, transform: StringifyTransform) -> str:
557
+ return '[' + transform(self.expr) + ']'
558
+
559
+ def get_id(self, idPrefix: str, version: int) -> str:
560
+ return 'ix' + idPrefix + self.expr.get_id(version)
561
+
562
+ def describe_signature(self, signode: TextElement, mode: str,
563
+ env: BuildEnvironment, symbol: Symbol) -> None:
564
+ signode += addnodes.desc_sig_punctuation('[', '[')
565
+ self.expr.describe_signature(signode, mode, env, symbol)
566
+ signode += addnodes.desc_sig_punctuation(']', ']')
567
+
568
+
569
+ class ASTPostfixMember(ASTPostfixOp):
570
+ def __init__(self, name: ASTNestedName) -> None:
571
+ self.name = name
572
+
573
+ def _stringify(self, transform: StringifyTransform) -> str:
574
+ return '.' + transform(self.name)
575
+
576
+ def get_id(self, idPrefix: str, version: int) -> str:
577
+ return 'dt' + idPrefix + self.name.get_id(version)
578
+
579
+ def describe_signature(self, signode: TextElement, mode: str,
580
+ env: BuildEnvironment, symbol: Symbol) -> None:
581
+ signode += addnodes.desc_sig_punctuation('.', '.')
582
+ self.name.describe_signature(signode, 'noneIsName', env, symbol)
583
+
584
+
585
+ class ASTPostfixMemberOfPointer(ASTPostfixOp):
586
+ def __init__(self, name: ASTNestedName) -> None:
587
+ self.name = name
588
+
589
+ def _stringify(self, transform: StringifyTransform) -> str:
590
+ return '->' + transform(self.name)
591
+
592
+ def get_id(self, idPrefix: str, version: int) -> str:
593
+ return 'pt' + idPrefix + self.name.get_id(version)
594
+
595
+ def describe_signature(self, signode: TextElement, mode: str,
596
+ env: BuildEnvironment, symbol: Symbol) -> None:
597
+ signode += addnodes.desc_sig_operator('->', '->')
598
+ self.name.describe_signature(signode, 'noneIsName', env, symbol)
599
+
600
+
601
+ class ASTPostfixInc(ASTPostfixOp):
602
+ def _stringify(self, transform: StringifyTransform) -> str:
603
+ return '++'
604
+
605
+ def get_id(self, idPrefix: str, version: int) -> str:
606
+ return 'pp' + idPrefix
607
+
608
+ def describe_signature(self, signode: TextElement, mode: str,
609
+ env: BuildEnvironment, symbol: Symbol) -> None:
610
+ signode += addnodes.desc_sig_operator('++', '++')
611
+
612
+
613
+ class ASTPostfixDec(ASTPostfixOp):
614
+ def _stringify(self, transform: StringifyTransform) -> str:
615
+ return '--'
616
+
617
+ def get_id(self, idPrefix: str, version: int) -> str:
618
+ return 'mm' + idPrefix
619
+
620
+ def describe_signature(self, signode: TextElement, mode: str,
621
+ env: BuildEnvironment, symbol: Symbol) -> None:
622
+ signode += addnodes.desc_sig_operator('--', '--')
623
+
624
+
625
+ class ASTPostfixCallExpr(ASTPostfixOp):
626
+ def __init__(self, lst: ASTParenExprList | ASTBracedInitList) -> None:
627
+ self.lst = lst
628
+
629
+ def _stringify(self, transform: StringifyTransform) -> str:
630
+ return transform(self.lst)
631
+
632
+ def get_id(self, idPrefix: str, version: int) -> str:
633
+ return ''.join([
634
+ 'cl',
635
+ idPrefix,
636
+ *(e.get_id(version) for e in self.lst.exprs),
637
+ 'E',
638
+ ])
639
+
640
+ def describe_signature(self, signode: TextElement, mode: str,
641
+ env: BuildEnvironment, symbol: Symbol) -> None:
642
+ self.lst.describe_signature(signode, mode, env, symbol)
643
+
644
+
645
+ class ASTPostfixExpr(ASTExpression):
646
+ def __init__(self, prefix: ASTType, postFixes: list[ASTPostfixOp]) -> None:
647
+ self.prefix = prefix
648
+ self.postFixes = postFixes
649
+
650
+ def _stringify(self, transform: StringifyTransform) -> str:
651
+ return ''.join([transform(self.prefix), *(transform(p) for p in self.postFixes)])
652
+
653
+ def get_id(self, version: int) -> str:
654
+ id = self.prefix.get_id(version)
655
+ for p in self.postFixes:
656
+ id = p.get_id(id, version)
657
+ return id
658
+
659
+ def describe_signature(self, signode: TextElement, mode: str,
660
+ env: BuildEnvironment, symbol: Symbol) -> None:
661
+ self.prefix.describe_signature(signode, mode, env, symbol)
662
+ for p in self.postFixes:
663
+ p.describe_signature(signode, mode, env, symbol)
664
+
665
+
666
+ class ASTExplicitCast(ASTExpression):
667
+ def __init__(self, cast: str, typ: ASTType, expr: ASTExpression) -> None:
668
+ assert cast in _id_explicit_cast
669
+ self.cast = cast
670
+ self.typ = typ
671
+ self.expr = expr
672
+
673
+ def _stringify(self, transform: StringifyTransform) -> str:
674
+ res = [self.cast]
675
+ res.append('<')
676
+ res.append(transform(self.typ))
677
+ res.append('>(')
678
+ res.append(transform(self.expr))
679
+ res.append(')')
680
+ return ''.join(res)
681
+
682
+ def get_id(self, version: int) -> str:
683
+ return (_id_explicit_cast[self.cast] +
684
+ self.typ.get_id(version) +
685
+ self.expr.get_id(version))
686
+
687
+ def describe_signature(self, signode: TextElement, mode: str,
688
+ env: BuildEnvironment, symbol: Symbol) -> None:
689
+ signode += addnodes.desc_sig_keyword(self.cast, self.cast)
690
+ signode += addnodes.desc_sig_punctuation('<', '<')
691
+ self.typ.describe_signature(signode, mode, env, symbol)
692
+ signode += addnodes.desc_sig_punctuation('>', '>')
693
+ signode += addnodes.desc_sig_punctuation('(', '(')
694
+ self.expr.describe_signature(signode, mode, env, symbol)
695
+ signode += addnodes.desc_sig_punctuation(')', ')')
696
+
697
+
698
+ class ASTTypeId(ASTExpression):
699
+ def __init__(self, typeOrExpr: ASTType | ASTExpression, isType: bool) -> None:
700
+ self.typeOrExpr = typeOrExpr
701
+ self.isType = isType
702
+
703
+ def _stringify(self, transform: StringifyTransform) -> str:
704
+ return 'typeid(' + transform(self.typeOrExpr) + ')'
705
+
706
+ def get_id(self, version: int) -> str:
707
+ prefix = 'ti' if self.isType else 'te'
708
+ return prefix + self.typeOrExpr.get_id(version)
709
+
710
+ def describe_signature(self, signode: TextElement, mode: str,
711
+ env: BuildEnvironment, symbol: Symbol) -> None:
712
+ signode += addnodes.desc_sig_keyword('typeid', 'typeid')
713
+ signode += addnodes.desc_sig_punctuation('(', '(')
714
+ self.typeOrExpr.describe_signature(signode, mode, env, symbol)
715
+ signode += addnodes.desc_sig_punctuation(')', ')')
716
+
717
+
718
+ # Unary expressions
719
+ ################################################################################
720
+
721
+ class ASTUnaryOpExpr(ASTExpression):
722
+ def __init__(self, op: str, expr: ASTExpression) -> None:
723
+ self.op = op
724
+ self.expr = expr
725
+
726
+ def _stringify(self, transform: StringifyTransform) -> str:
727
+ if self.op[0] in 'cn':
728
+ return self.op + " " + transform(self.expr)
729
+ else:
730
+ return self.op + transform(self.expr)
731
+
732
+ def get_id(self, version: int) -> str:
733
+ return _id_operator_unary_v2[self.op] + self.expr.get_id(version)
734
+
735
+ def describe_signature(self, signode: TextElement, mode: str,
736
+ env: BuildEnvironment, symbol: Symbol) -> None:
737
+ if self.op[0] in 'cn':
738
+ signode += addnodes.desc_sig_keyword(self.op, self.op)
739
+ signode += addnodes.desc_sig_space()
740
+ else:
741
+ signode += addnodes.desc_sig_operator(self.op, self.op)
742
+ self.expr.describe_signature(signode, mode, env, symbol)
743
+
744
+
745
+ class ASTSizeofParamPack(ASTExpression):
746
+ def __init__(self, identifier: ASTIdentifier) -> None:
747
+ self.identifier = identifier
748
+
749
+ def _stringify(self, transform: StringifyTransform) -> str:
750
+ return "sizeof...(" + transform(self.identifier) + ")"
751
+
752
+ def get_id(self, version: int) -> str:
753
+ return 'sZ' + self.identifier.get_id(version)
754
+
755
+ def describe_signature(self, signode: TextElement, mode: str,
756
+ env: BuildEnvironment, symbol: Symbol) -> None:
757
+ signode += addnodes.desc_sig_keyword('sizeof', 'sizeof')
758
+ signode += addnodes.desc_sig_punctuation('...', '...')
759
+ signode += addnodes.desc_sig_punctuation('(', '(')
760
+ self.identifier.describe_signature(signode, 'markType', env,
761
+ symbol=symbol, prefix="", templateArgs="")
762
+ signode += addnodes.desc_sig_punctuation(')', ')')
763
+
764
+
765
+ class ASTSizeofType(ASTExpression):
766
+ def __init__(self, typ: ASTType) -> None:
767
+ self.typ = typ
768
+
769
+ def _stringify(self, transform: StringifyTransform) -> str:
770
+ return "sizeof(" + transform(self.typ) + ")"
771
+
772
+ def get_id(self, version: int) -> str:
773
+ return 'st' + self.typ.get_id(version)
774
+
775
+ def describe_signature(self, signode: TextElement, mode: str,
776
+ env: BuildEnvironment, symbol: Symbol) -> None:
777
+ signode += addnodes.desc_sig_keyword('sizeof', 'sizeof')
778
+ signode += addnodes.desc_sig_punctuation('(', '(')
779
+ self.typ.describe_signature(signode, mode, env, symbol)
780
+ signode += addnodes.desc_sig_punctuation(')', ')')
781
+
782
+
783
+ class ASTSizeofExpr(ASTExpression):
784
+ def __init__(self, expr: ASTExpression) -> None:
785
+ self.expr = expr
786
+
787
+ def _stringify(self, transform: StringifyTransform) -> str:
788
+ return "sizeof " + transform(self.expr)
789
+
790
+ def get_id(self, version: int) -> str:
791
+ return 'sz' + self.expr.get_id(version)
792
+
793
+ def describe_signature(self, signode: TextElement, mode: str,
794
+ env: BuildEnvironment, symbol: Symbol) -> None:
795
+ signode += addnodes.desc_sig_keyword('sizeof', 'sizeof')
796
+ signode += addnodes.desc_sig_space()
797
+ self.expr.describe_signature(signode, mode, env, symbol)
798
+
799
+
800
+ class ASTAlignofExpr(ASTExpression):
801
+ def __init__(self, typ: ASTType) -> None:
802
+ self.typ = typ
803
+
804
+ def _stringify(self, transform: StringifyTransform) -> str:
805
+ return "alignof(" + transform(self.typ) + ")"
806
+
807
+ def get_id(self, version: int) -> str:
808
+ return 'at' + self.typ.get_id(version)
809
+
810
+ def describe_signature(self, signode: TextElement, mode: str,
811
+ env: BuildEnvironment, symbol: Symbol) -> None:
812
+ signode += addnodes.desc_sig_keyword('alignof', 'alignof')
813
+ signode += addnodes.desc_sig_punctuation('(', '(')
814
+ self.typ.describe_signature(signode, mode, env, symbol)
815
+ signode += addnodes.desc_sig_punctuation(')', ')')
816
+
817
+
818
+ class ASTNoexceptExpr(ASTExpression):
819
+ def __init__(self, expr: ASTExpression) -> None:
820
+ self.expr = expr
821
+
822
+ def _stringify(self, transform: StringifyTransform) -> str:
823
+ return 'noexcept(' + transform(self.expr) + ')'
824
+
825
+ def get_id(self, version: int) -> str:
826
+ return 'nx' + self.expr.get_id(version)
827
+
828
+ def describe_signature(self, signode: TextElement, mode: str,
829
+ env: BuildEnvironment, symbol: Symbol) -> None:
830
+ signode += addnodes.desc_sig_keyword('noexcept', 'noexcept')
831
+ signode += addnodes.desc_sig_punctuation('(', '(')
832
+ self.expr.describe_signature(signode, mode, env, symbol)
833
+ signode += addnodes.desc_sig_punctuation(')', ')')
834
+
835
+
836
+ class ASTNewExpr(ASTExpression):
837
+ def __init__(self, rooted: bool, isNewTypeId: bool, typ: ASTType,
838
+ initList: ASTParenExprList | ASTBracedInitList) -> None:
839
+ self.rooted = rooted
840
+ self.isNewTypeId = isNewTypeId
841
+ self.typ = typ
842
+ self.initList = initList
843
+
844
+ def _stringify(self, transform: StringifyTransform) -> str:
845
+ res = []
846
+ if self.rooted:
847
+ res.append('::')
848
+ res.append('new ')
849
+ # TODO: placement
850
+ if self.isNewTypeId:
851
+ res.append(transform(self.typ))
852
+ else:
853
+ raise AssertionError
854
+ if self.initList is not None:
855
+ res.append(transform(self.initList))
856
+ return ''.join(res)
857
+
858
+ def get_id(self, version: int) -> str:
859
+ # the array part will be in the type mangling, so na is not used
860
+ res = ['nw']
861
+ # TODO: placement
862
+ res.append('_')
863
+ res.append(self.typ.get_id(version))
864
+ if self.initList is not None:
865
+ res.append(self.initList.get_id(version))
866
+ else:
867
+ res.append('E')
868
+ return ''.join(res)
869
+
870
+ def describe_signature(self, signode: TextElement, mode: str,
871
+ env: BuildEnvironment, symbol: Symbol) -> None:
872
+ if self.rooted:
873
+ signode += addnodes.desc_sig_punctuation('::', '::')
874
+ signode += addnodes.desc_sig_keyword('new', 'new')
875
+ signode += addnodes.desc_sig_space()
876
+ # TODO: placement
877
+ if self.isNewTypeId:
878
+ self.typ.describe_signature(signode, mode, env, symbol)
879
+ else:
880
+ raise AssertionError
881
+ if self.initList is not None:
882
+ self.initList.describe_signature(signode, mode, env, symbol)
883
+
884
+
885
+ class ASTDeleteExpr(ASTExpression):
886
+ def __init__(self, rooted: bool, array: bool, expr: ASTExpression) -> None:
887
+ self.rooted = rooted
888
+ self.array = array
889
+ self.expr = expr
890
+
891
+ def _stringify(self, transform: StringifyTransform) -> str:
892
+ res = []
893
+ if self.rooted:
894
+ res.append('::')
895
+ res.append('delete ')
896
+ if self.array:
897
+ res.append('[] ')
898
+ res.append(transform(self.expr))
899
+ return ''.join(res)
900
+
901
+ def get_id(self, version: int) -> str:
902
+ if self.array:
903
+ id = "da"
904
+ else:
905
+ id = "dl"
906
+ return id + self.expr.get_id(version)
907
+
908
+ def describe_signature(self, signode: TextElement, mode: str,
909
+ env: BuildEnvironment, symbol: Symbol) -> None:
910
+ if self.rooted:
911
+ signode += addnodes.desc_sig_punctuation('::', '::')
912
+ signode += addnodes.desc_sig_keyword('delete', 'delete')
913
+ signode += addnodes.desc_sig_space()
914
+ if self.array:
915
+ signode += addnodes.desc_sig_punctuation('[]', '[]')
916
+ signode += addnodes.desc_sig_space()
917
+ self.expr.describe_signature(signode, mode, env, symbol)
918
+
919
+
920
+ # Other expressions
921
+ ################################################################################
922
+
923
+ class ASTCastExpr(ASTExpression):
924
+ def __init__(self, typ: ASTType, expr: ASTExpression) -> None:
925
+ self.typ = typ
926
+ self.expr = expr
927
+
928
+ def _stringify(self, transform: StringifyTransform) -> str:
929
+ res = ['(']
930
+ res.append(transform(self.typ))
931
+ res.append(')')
932
+ res.append(transform(self.expr))
933
+ return ''.join(res)
934
+
935
+ def get_id(self, version: int) -> str:
936
+ return 'cv' + self.typ.get_id(version) + self.expr.get_id(version)
937
+
938
+ def describe_signature(self, signode: TextElement, mode: str,
939
+ env: BuildEnvironment, symbol: Symbol) -> None:
940
+ signode += addnodes.desc_sig_punctuation('(', '(')
941
+ self.typ.describe_signature(signode, mode, env, symbol)
942
+ signode += addnodes.desc_sig_punctuation(')', ')')
943
+ self.expr.describe_signature(signode, mode, env, symbol)
944
+
945
+
946
+ class ASTBinOpExpr(ASTExpression):
947
+ def __init__(self, exprs: list[ASTExpression], ops: list[str]) -> None:
948
+ assert len(exprs) > 0
949
+ assert len(exprs) == len(ops) + 1
950
+ self.exprs = exprs
951
+ self.ops = ops
952
+
953
+ def _stringify(self, transform: StringifyTransform) -> str:
954
+ res = []
955
+ res.append(transform(self.exprs[0]))
956
+ for i in range(1, len(self.exprs)):
957
+ res.append(' ')
958
+ res.append(self.ops[i - 1])
959
+ res.append(' ')
960
+ res.append(transform(self.exprs[i]))
961
+ return ''.join(res)
962
+
963
+ def get_id(self, version: int) -> str:
964
+ assert version >= 2
965
+ res = []
966
+ for i in range(len(self.ops)):
967
+ res.append(_id_operator_v2[self.ops[i]])
968
+ res.append(self.exprs[i].get_id(version))
969
+ res.append(self.exprs[-1].get_id(version))
970
+ return ''.join(res)
971
+
972
+ def describe_signature(self, signode: TextElement, mode: str,
973
+ env: BuildEnvironment, symbol: Symbol) -> None:
974
+ self.exprs[0].describe_signature(signode, mode, env, symbol)
975
+ for i in range(1, len(self.exprs)):
976
+ signode += addnodes.desc_sig_space()
977
+ op = self.ops[i - 1]
978
+ if ord(op[0]) >= ord('a') and ord(op[0]) <= ord('z'):
979
+ signode += addnodes.desc_sig_keyword(op, op)
980
+ else:
981
+ signode += addnodes.desc_sig_operator(op, op)
982
+ signode += addnodes.desc_sig_space()
983
+ self.exprs[i].describe_signature(signode, mode, env, symbol)
984
+
985
+
986
+ class ASTConditionalExpr(ASTExpression):
987
+ def __init__(self, ifExpr: ASTExpression, thenExpr: ASTExpression,
988
+ elseExpr: ASTExpression) -> None:
989
+ self.ifExpr = ifExpr
990
+ self.thenExpr = thenExpr
991
+ self.elseExpr = elseExpr
992
+
993
+ def _stringify(self, transform: StringifyTransform) -> str:
994
+ res = []
995
+ res.append(transform(self.ifExpr))
996
+ res.append(' ? ')
997
+ res.append(transform(self.thenExpr))
998
+ res.append(' : ')
999
+ res.append(transform(self.elseExpr))
1000
+ return ''.join(res)
1001
+
1002
+ def get_id(self, version: int) -> str:
1003
+ assert version >= 2
1004
+ res = []
1005
+ res.append(_id_operator_v2['?'])
1006
+ res.append(self.ifExpr.get_id(version))
1007
+ res.append(self.thenExpr.get_id(version))
1008
+ res.append(self.elseExpr.get_id(version))
1009
+ return ''.join(res)
1010
+
1011
+ def describe_signature(self, signode: TextElement, mode: str,
1012
+ env: BuildEnvironment, symbol: Symbol) -> None:
1013
+ self.ifExpr.describe_signature(signode, mode, env, symbol)
1014
+ signode += addnodes.desc_sig_space()
1015
+ signode += addnodes.desc_sig_operator('?', '?')
1016
+ signode += addnodes.desc_sig_space()
1017
+ self.thenExpr.describe_signature(signode, mode, env, symbol)
1018
+ signode += addnodes.desc_sig_space()
1019
+ signode += addnodes.desc_sig_operator(':', ':')
1020
+ signode += addnodes.desc_sig_space()
1021
+ self.elseExpr.describe_signature(signode, mode, env, symbol)
1022
+
1023
+
1024
+ class ASTBracedInitList(ASTBase):
1025
+ def __init__(self, exprs: list[ASTExpression | ASTBracedInitList],
1026
+ trailingComma: bool) -> None:
1027
+ self.exprs = exprs
1028
+ self.trailingComma = trailingComma
1029
+
1030
+ def get_id(self, version: int) -> str:
1031
+ return "il%sE" % ''.join(e.get_id(version) for e in self.exprs)
1032
+
1033
+ def _stringify(self, transform: StringifyTransform) -> str:
1034
+ exprs = ', '.join(transform(e) for e in self.exprs)
1035
+ trailingComma = ',' if self.trailingComma else ''
1036
+ return f'{{{exprs}{trailingComma}}}'
1037
+
1038
+ def describe_signature(self, signode: TextElement, mode: str,
1039
+ env: BuildEnvironment, symbol: Symbol) -> None:
1040
+ verify_description_mode(mode)
1041
+ signode += addnodes.desc_sig_punctuation('{', '{')
1042
+ first = True
1043
+ for e in self.exprs:
1044
+ if not first:
1045
+ signode += addnodes.desc_sig_punctuation(',', ',')
1046
+ signode += addnodes.desc_sig_space()
1047
+ else:
1048
+ first = False
1049
+ e.describe_signature(signode, mode, env, symbol)
1050
+ if self.trailingComma:
1051
+ signode += addnodes.desc_sig_punctuation(',', ',')
1052
+ signode += addnodes.desc_sig_punctuation('}', '}')
1053
+
1054
+
1055
+ class ASTAssignmentExpr(ASTExpression):
1056
+ def __init__(self, leftExpr: ASTExpression, op: str,
1057
+ rightExpr: ASTExpression | ASTBracedInitList) -> None:
1058
+ self.leftExpr = leftExpr
1059
+ self.op = op
1060
+ self.rightExpr = rightExpr
1061
+
1062
+ def _stringify(self, transform: StringifyTransform) -> str:
1063
+ res = []
1064
+ res.append(transform(self.leftExpr))
1065
+ res.append(' ')
1066
+ res.append(self.op)
1067
+ res.append(' ')
1068
+ res.append(transform(self.rightExpr))
1069
+ return ''.join(res)
1070
+
1071
+ def get_id(self, version: int) -> str:
1072
+ # we end up generating the ID from left to right, instead of right to left
1073
+ res = []
1074
+ res.append(_id_operator_v2[self.op])
1075
+ res.append(self.leftExpr.get_id(version))
1076
+ res.append(self.rightExpr.get_id(version))
1077
+ return ''.join(res)
1078
+
1079
+ def describe_signature(self, signode: TextElement, mode: str,
1080
+ env: BuildEnvironment, symbol: Symbol) -> None:
1081
+ self.leftExpr.describe_signature(signode, mode, env, symbol)
1082
+ signode += addnodes.desc_sig_space()
1083
+ if ord(self.op[0]) >= ord('a') and ord(self.op[0]) <= ord('z'):
1084
+ signode += addnodes.desc_sig_keyword(self.op, self.op)
1085
+ else:
1086
+ signode += addnodes.desc_sig_operator(self.op, self.op)
1087
+ signode += addnodes.desc_sig_space()
1088
+ self.rightExpr.describe_signature(signode, mode, env, symbol)
1089
+
1090
+
1091
+ class ASTCommaExpr(ASTExpression):
1092
+ def __init__(self, exprs: list[ASTExpression]) -> None:
1093
+ assert len(exprs) > 0
1094
+ self.exprs = exprs
1095
+
1096
+ def _stringify(self, transform: StringifyTransform) -> str:
1097
+ return ', '.join(transform(e) for e in self.exprs)
1098
+
1099
+ def get_id(self, version: int) -> str:
1100
+ id_ = _id_operator_v2[',']
1101
+ res = []
1102
+ for i in range(len(self.exprs) - 1):
1103
+ res.append(id_)
1104
+ res.append(self.exprs[i].get_id(version))
1105
+ res.append(self.exprs[-1].get_id(version))
1106
+ return ''.join(res)
1107
+
1108
+ def describe_signature(self, signode: TextElement, mode: str,
1109
+ env: BuildEnvironment, symbol: Symbol) -> None:
1110
+ self.exprs[0].describe_signature(signode, mode, env, symbol)
1111
+ for i in range(1, len(self.exprs)):
1112
+ signode += addnodes.desc_sig_punctuation(',', ',')
1113
+ signode += addnodes.desc_sig_space()
1114
+ self.exprs[i].describe_signature(signode, mode, env, symbol)
1115
+
1116
+
1117
+ class ASTFallbackExpr(ASTExpression):
1118
+ def __init__(self, expr: str) -> None:
1119
+ self.expr = expr
1120
+
1121
+ def _stringify(self, transform: StringifyTransform) -> str:
1122
+ return self.expr
1123
+
1124
+ def get_id(self, version: int) -> str:
1125
+ return str(self.expr)
1126
+
1127
+ def describe_signature(self, signode: TextElement, mode: str,
1128
+ env: BuildEnvironment, symbol: Symbol) -> None:
1129
+ signode += nodes.literal(self.expr, self.expr)
1130
+
1131
+
1132
+ ################################################################################
1133
+ # Types
1134
+ ################################################################################
1135
+
1136
+ # Things for ASTNestedName
1137
+ ################################################################################
1138
+
1139
+ class ASTOperator(ASTBase):
1140
+ def __eq__(self, other: object) -> bool:
1141
+ raise NotImplementedError(repr(self))
1142
+
1143
+ def is_anon(self) -> bool:
1144
+ return False
1145
+
1146
+ def is_operator(self) -> bool:
1147
+ return True
1148
+
1149
+ def get_id(self, version: int) -> str:
1150
+ raise NotImplementedError
1151
+
1152
+ def _describe_identifier(self, signode: TextElement, identnode: TextElement,
1153
+ env: BuildEnvironment, symbol: Symbol) -> None:
1154
+ """Render the prefix into signode, and the last part into identnode."""
1155
+ raise NotImplementedError
1156
+
1157
+ def describe_signature(self, signode: TextElement, mode: str,
1158
+ env: BuildEnvironment, prefix: str, templateArgs: str,
1159
+ symbol: Symbol) -> None:
1160
+ verify_description_mode(mode)
1161
+ if mode == 'lastIsName':
1162
+ mainName = addnodes.desc_name()
1163
+ self._describe_identifier(mainName, mainName, env, symbol)
1164
+ signode += mainName
1165
+ elif mode == 'markType':
1166
+ targetText = prefix + str(self) + templateArgs
1167
+ pnode = addnodes.pending_xref('', refdomain='cpp',
1168
+ reftype='identifier',
1169
+ reftarget=targetText, modname=None,
1170
+ classname=None)
1171
+ pnode['cpp:parent_key'] = symbol.get_lookup_key()
1172
+ # Render the identifier part, but collapse it into a string
1173
+ # and make that the a link to this operator.
1174
+ # E.g., if it is 'operator SomeType', then 'SomeType' becomes
1175
+ # a link to the operator, not to 'SomeType'.
1176
+ container = nodes.literal()
1177
+ self._describe_identifier(signode, container, env, symbol)
1178
+ txt = container.astext()
1179
+ pnode += addnodes.desc_name(txt, txt)
1180
+ signode += pnode
1181
+ else:
1182
+ addName = addnodes.desc_addname()
1183
+ self._describe_identifier(addName, addName, env, symbol)
1184
+ signode += addName
1185
+
1186
+
1187
+ class ASTOperatorBuildIn(ASTOperator):
1188
+ def __init__(self, op: str) -> None:
1189
+ self.op = op
1190
+
1191
+ def __eq__(self, other: object) -> bool:
1192
+ if not isinstance(other, ASTOperatorBuildIn):
1193
+ return NotImplemented
1194
+ return self.op == other.op
1195
+
1196
+ def get_id(self, version: int) -> str:
1197
+ if version == 1:
1198
+ ids = _id_operator_v1
1199
+ if self.op not in ids:
1200
+ raise NoOldIdError
1201
+ else:
1202
+ ids = _id_operator_v2
1203
+ if self.op not in ids:
1204
+ raise Exception('Internal error: Built-in operator "%s" can not '
1205
+ 'be mapped to an id.' % self.op)
1206
+ return ids[self.op]
1207
+
1208
+ def _stringify(self, transform: StringifyTransform) -> str:
1209
+ if self.op in ('new', 'new[]', 'delete', 'delete[]') or self.op[0] in "abcnox":
1210
+ return 'operator ' + self.op
1211
+ else:
1212
+ return 'operator' + self.op
1213
+
1214
+ def _describe_identifier(self, signode: TextElement, identnode: TextElement,
1215
+ env: BuildEnvironment, symbol: Symbol) -> None:
1216
+ signode += addnodes.desc_sig_keyword('operator', 'operator')
1217
+ if self.op in ('new', 'new[]', 'delete', 'delete[]') or self.op[0] in "abcnox":
1218
+ signode += addnodes.desc_sig_space()
1219
+ identnode += addnodes.desc_sig_operator(self.op, self.op)
1220
+
1221
+
1222
+ class ASTOperatorLiteral(ASTOperator):
1223
+ def __init__(self, identifier: ASTIdentifier) -> None:
1224
+ self.identifier = identifier
1225
+
1226
+ def __eq__(self, other: object) -> bool:
1227
+ if not isinstance(other, ASTOperatorLiteral):
1228
+ return NotImplemented
1229
+ return self.identifier == other.identifier
1230
+
1231
+ def get_id(self, version: int) -> str:
1232
+ if version == 1:
1233
+ raise NoOldIdError
1234
+ return 'li' + self.identifier.get_id(version)
1235
+
1236
+ def _stringify(self, transform: StringifyTransform) -> str:
1237
+ return 'operator""' + transform(self.identifier)
1238
+
1239
+ def _describe_identifier(self, signode: TextElement, identnode: TextElement,
1240
+ env: BuildEnvironment, symbol: Symbol) -> None:
1241
+ signode += addnodes.desc_sig_keyword('operator', 'operator')
1242
+ signode += addnodes.desc_sig_literal_string('""', '""')
1243
+ self.identifier.describe_signature(identnode, 'markType', env, '', '', symbol)
1244
+
1245
+
1246
+ class ASTOperatorType(ASTOperator):
1247
+ def __init__(self, type: ASTType) -> None:
1248
+ self.type = type
1249
+
1250
+ def __eq__(self, other: object) -> bool:
1251
+ if not isinstance(other, ASTOperatorType):
1252
+ return NotImplemented
1253
+ return self.type == other.type
1254
+
1255
+ def get_id(self, version: int) -> str:
1256
+ if version == 1:
1257
+ return 'castto-%s-operator' % self.type.get_id(version)
1258
+ else:
1259
+ return 'cv' + self.type.get_id(version)
1260
+
1261
+ def _stringify(self, transform: StringifyTransform) -> str:
1262
+ return f'operator {transform(self.type)}'
1263
+
1264
+ def get_name_no_template(self) -> str:
1265
+ return str(self)
1266
+
1267
+ def _describe_identifier(self, signode: TextElement, identnode: TextElement,
1268
+ env: BuildEnvironment, symbol: Symbol) -> None:
1269
+ signode += addnodes.desc_sig_keyword('operator', 'operator')
1270
+ signode += addnodes.desc_sig_space()
1271
+ self.type.describe_signature(identnode, 'markType', env, symbol)
1272
+
1273
+
1274
+ class ASTTemplateArgConstant(ASTBase):
1275
+ def __init__(self, value: ASTExpression) -> None:
1276
+ self.value = value
1277
+
1278
+ def _stringify(self, transform: StringifyTransform) -> str:
1279
+ return transform(self.value)
1280
+
1281
+ def get_id(self, version: int) -> str:
1282
+ if version == 1:
1283
+ return str(self).replace(' ', '-')
1284
+ if version == 2:
1285
+ return 'X' + str(self) + 'E'
1286
+ return 'X' + self.value.get_id(version) + 'E'
1287
+
1288
+ def describe_signature(self, signode: TextElement, mode: str,
1289
+ env: BuildEnvironment, symbol: Symbol) -> None:
1290
+ verify_description_mode(mode)
1291
+ self.value.describe_signature(signode, mode, env, symbol)
1292
+
1293
+
1294
+ class ASTTemplateArgs(ASTBase):
1295
+ def __init__(self, args: list[ASTType | ASTTemplateArgConstant],
1296
+ packExpansion: bool) -> None:
1297
+ assert args is not None
1298
+ self.args = args
1299
+ self.packExpansion = packExpansion
1300
+
1301
+ def get_id(self, version: int) -> str:
1302
+ if version == 1:
1303
+ res = []
1304
+ res.append(':')
1305
+ res.append('.'.join(a.get_id(version) for a in self.args))
1306
+ res.append(':')
1307
+ return ''.join(res)
1308
+
1309
+ res = []
1310
+ res.append('I')
1311
+ if len(self.args) > 0:
1312
+ for a in self.args[:-1]:
1313
+ res.append(a.get_id(version))
1314
+ if self.packExpansion:
1315
+ res.append('J')
1316
+ res.append(self.args[-1].get_id(version))
1317
+ if self.packExpansion:
1318
+ res.append('E')
1319
+ res.append('E')
1320
+ return ''.join(res)
1321
+
1322
+ def _stringify(self, transform: StringifyTransform) -> str:
1323
+ res = ', '.join(transform(a) for a in self.args)
1324
+ if self.packExpansion:
1325
+ res += '...'
1326
+ return '<' + res + '>'
1327
+
1328
+ def describe_signature(self, signode: TextElement, mode: str,
1329
+ env: BuildEnvironment, symbol: Symbol) -> None:
1330
+ verify_description_mode(mode)
1331
+ signode += addnodes.desc_sig_punctuation('<', '<')
1332
+ first = True
1333
+ for a in self.args:
1334
+ if not first:
1335
+ signode += addnodes.desc_sig_punctuation(',', ',')
1336
+ signode += addnodes.desc_sig_space()
1337
+ first = False
1338
+ a.describe_signature(signode, 'markType', env, symbol=symbol)
1339
+ if self.packExpansion:
1340
+ signode += addnodes.desc_sig_punctuation('...', '...')
1341
+ signode += addnodes.desc_sig_punctuation('>', '>')
1342
+
1343
+
1344
+ # Main part of declarations
1345
+ ################################################################################
1346
+
1347
+ class ASTTrailingTypeSpec(ASTBase):
1348
+ def get_id(self, version: int) -> str:
1349
+ raise NotImplementedError(repr(self))
1350
+
1351
+ def describe_signature(self, signode: TextElement, mode: str,
1352
+ env: BuildEnvironment, symbol: Symbol) -> None:
1353
+ raise NotImplementedError(repr(self))
1354
+
1355
+
1356
+ class ASTTrailingTypeSpecFundamental(ASTTrailingTypeSpec):
1357
+ def __init__(self, names: list[str], canonNames: list[str]) -> None:
1358
+ assert len(names) != 0
1359
+ assert len(names) == len(canonNames), (names, canonNames)
1360
+ self.names = names
1361
+ # the canonical name list is for ID lookup
1362
+ self.canonNames = canonNames
1363
+
1364
+ def _stringify(self, transform: StringifyTransform) -> str:
1365
+ return ' '.join(self.names)
1366
+
1367
+ def get_id(self, version: int) -> str:
1368
+ if version == 1:
1369
+ res = []
1370
+ for a in self.canonNames:
1371
+ if a in _id_fundamental_v1:
1372
+ res.append(_id_fundamental_v1[a])
1373
+ else:
1374
+ res.append(a)
1375
+ return '-'.join(res)
1376
+
1377
+ txt = ' '.join(self.canonNames)
1378
+ if txt not in _id_fundamental_v2:
1379
+ raise Exception(
1380
+ 'Semi-internal error: Fundamental type "%s" can not be mapped '
1381
+ 'to an ID. Is it a true fundamental type? If not so, the '
1382
+ 'parser should have rejected it.' % txt)
1383
+ return _id_fundamental_v2[txt]
1384
+
1385
+ def describe_signature(self, signode: TextElement, mode: str,
1386
+ env: BuildEnvironment, symbol: Symbol) -> None:
1387
+ first = True
1388
+ for n in self.names:
1389
+ if not first:
1390
+ signode += addnodes.desc_sig_space()
1391
+ else:
1392
+ first = False
1393
+ signode += addnodes.desc_sig_keyword_type(n, n)
1394
+
1395
+
1396
+ class ASTTrailingTypeSpecDecltypeAuto(ASTTrailingTypeSpec):
1397
+ def _stringify(self, transform: StringifyTransform) -> str:
1398
+ return 'decltype(auto)'
1399
+
1400
+ def get_id(self, version: int) -> str:
1401
+ if version == 1:
1402
+ raise NoOldIdError
1403
+ return 'Dc'
1404
+
1405
+ def describe_signature(self, signode: TextElement, mode: str,
1406
+ env: BuildEnvironment, symbol: Symbol) -> None:
1407
+ signode += addnodes.desc_sig_keyword('decltype', 'decltype')
1408
+ signode += addnodes.desc_sig_punctuation('(', '(')
1409
+ signode += addnodes.desc_sig_keyword('auto', 'auto')
1410
+ signode += addnodes.desc_sig_punctuation(')', ')')
1411
+
1412
+
1413
+ class ASTTrailingTypeSpecDecltype(ASTTrailingTypeSpec):
1414
+ def __init__(self, expr: ASTExpression) -> None:
1415
+ self.expr = expr
1416
+
1417
+ def _stringify(self, transform: StringifyTransform) -> str:
1418
+ return 'decltype(' + transform(self.expr) + ')'
1419
+
1420
+ def get_id(self, version: int) -> str:
1421
+ if version == 1:
1422
+ raise NoOldIdError
1423
+ return 'DT' + self.expr.get_id(version) + "E"
1424
+
1425
+ def describe_signature(self, signode: TextElement, mode: str,
1426
+ env: BuildEnvironment, symbol: Symbol) -> None:
1427
+ signode += addnodes.desc_sig_keyword('decltype', 'decltype')
1428
+ signode += addnodes.desc_sig_punctuation('(', '(')
1429
+ self.expr.describe_signature(signode, mode, env, symbol)
1430
+ signode += addnodes.desc_sig_punctuation(')', ')')
1431
+
1432
+
1433
+ class ASTTrailingTypeSpecName(ASTTrailingTypeSpec):
1434
+ def __init__(self, prefix: str, nestedName: ASTNestedName,
1435
+ placeholderType: str | None) -> None:
1436
+ self.prefix = prefix
1437
+ self.nestedName = nestedName
1438
+ self.placeholderType = placeholderType
1439
+
1440
+ @property
1441
+ def name(self) -> ASTNestedName:
1442
+ return self.nestedName
1443
+
1444
+ def get_id(self, version: int) -> str:
1445
+ return self.nestedName.get_id(version)
1446
+
1447
+ def _stringify(self, transform: StringifyTransform) -> str:
1448
+ res = []
1449
+ if self.prefix:
1450
+ res.append(self.prefix)
1451
+ res.append(' ')
1452
+ res.append(transform(self.nestedName))
1453
+ if self.placeholderType is not None:
1454
+ res.append(' ')
1455
+ res.append(self.placeholderType)
1456
+ return ''.join(res)
1457
+
1458
+ def describe_signature(self, signode: TextElement, mode: str,
1459
+ env: BuildEnvironment, symbol: Symbol) -> None:
1460
+ if self.prefix:
1461
+ signode += addnodes.desc_sig_keyword(self.prefix, self.prefix)
1462
+ signode += addnodes.desc_sig_space()
1463
+ self.nestedName.describe_signature(signode, mode, env, symbol=symbol)
1464
+ if self.placeholderType is not None:
1465
+ signode += addnodes.desc_sig_space()
1466
+ if self.placeholderType == 'auto':
1467
+ signode += addnodes.desc_sig_keyword('auto', 'auto')
1468
+ elif self.placeholderType == 'decltype(auto)':
1469
+ signode += addnodes.desc_sig_keyword('decltype', 'decltype')
1470
+ signode += addnodes.desc_sig_punctuation('(', '(')
1471
+ signode += addnodes.desc_sig_keyword('auto', 'auto')
1472
+ signode += addnodes.desc_sig_punctuation(')', ')')
1473
+ else:
1474
+ raise AssertionError(self.placeholderType)
1475
+
1476
+
1477
+ class ASTFunctionParameter(ASTBase):
1478
+ def __init__(self, arg: ASTTypeWithInit | ASTTemplateParamConstrainedTypeWithInit,
1479
+ ellipsis: bool = False) -> None:
1480
+ self.arg = arg
1481
+ self.ellipsis = ellipsis
1482
+
1483
+ def get_id(
1484
+ self, version: int, objectType: str | None = None, symbol: Symbol | None = None,
1485
+ ) -> str:
1486
+ # this is not part of the normal name mangling in C++
1487
+ if symbol:
1488
+ # the anchor will be our parent
1489
+ return symbol.parent.declaration.get_id(version, prefixed=False)
1490
+ # else, do the usual
1491
+ if self.ellipsis:
1492
+ return 'z'
1493
+ else:
1494
+ return self.arg.get_id(version)
1495
+
1496
+ def _stringify(self, transform: StringifyTransform) -> str:
1497
+ if self.ellipsis:
1498
+ return '...'
1499
+ else:
1500
+ return transform(self.arg)
1501
+
1502
+ def describe_signature(self, signode: TextElement, mode: str,
1503
+ env: BuildEnvironment, symbol: Symbol) -> None:
1504
+ verify_description_mode(mode)
1505
+ if self.ellipsis:
1506
+ signode += addnodes.desc_sig_punctuation('...', '...')
1507
+ else:
1508
+ self.arg.describe_signature(signode, mode, env, symbol=symbol)
1509
+
1510
+
1511
+ class ASTNoexceptSpec(ASTBase):
1512
+ def __init__(self, expr: ASTExpression | None) -> None:
1513
+ self.expr = expr
1514
+
1515
+ def _stringify(self, transform: StringifyTransform) -> str:
1516
+ if self.expr:
1517
+ return 'noexcept(' + transform(self.expr) + ')'
1518
+ return 'noexcept'
1519
+
1520
+ def describe_signature(self, signode: TextElement, mode: str,
1521
+ env: BuildEnvironment, symbol: Symbol) -> None:
1522
+ signode += addnodes.desc_sig_keyword('noexcept', 'noexcept')
1523
+ if self.expr:
1524
+ signode += addnodes.desc_sig_punctuation('(', '(')
1525
+ self.expr.describe_signature(signode, 'markType', env, symbol)
1526
+ signode += addnodes.desc_sig_punctuation(')', ')')
1527
+
1528
+
1529
+ class ASTParametersQualifiers(ASTBase):
1530
+ def __init__(self, args: list[ASTFunctionParameter], volatile: bool, const: bool,
1531
+ refQual: str | None, exceptionSpec: ASTNoexceptSpec,
1532
+ trailingReturn: ASTType,
1533
+ override: bool, final: bool, attrs: ASTAttributeList,
1534
+ initializer: str | None) -> None:
1535
+ self.args = args
1536
+ self.volatile = volatile
1537
+ self.const = const
1538
+ self.refQual = refQual
1539
+ self.exceptionSpec = exceptionSpec
1540
+ self.trailingReturn = trailingReturn
1541
+ self.override = override
1542
+ self.final = final
1543
+ self.attrs = attrs
1544
+ self.initializer = initializer
1545
+
1546
+ @property
1547
+ def function_params(self) -> list[ASTFunctionParameter]:
1548
+ return self.args
1549
+
1550
+ def get_modifiers_id(self, version: int) -> str:
1551
+ res = []
1552
+ if self.volatile:
1553
+ res.append('V')
1554
+ if self.const:
1555
+ if version == 1:
1556
+ res.append('C')
1557
+ else:
1558
+ res.append('K')
1559
+ if self.refQual == '&&':
1560
+ res.append('O')
1561
+ elif self.refQual == '&':
1562
+ res.append('R')
1563
+ return ''.join(res)
1564
+
1565
+ def get_param_id(self, version: int) -> str:
1566
+ if version == 1:
1567
+ if len(self.args) == 0:
1568
+ return ''
1569
+ else:
1570
+ return '__' + '.'.join(a.get_id(version) for a in self.args)
1571
+ if len(self.args) == 0:
1572
+ return 'v'
1573
+ else:
1574
+ return ''.join(a.get_id(version) for a in self.args)
1575
+
1576
+ def _stringify(self, transform: StringifyTransform) -> str:
1577
+ res = []
1578
+ res.append('(')
1579
+ first = True
1580
+ for a in self.args:
1581
+ if not first:
1582
+ res.append(', ')
1583
+ first = False
1584
+ res.append(str(a))
1585
+ res.append(')')
1586
+ if self.volatile:
1587
+ res.append(' volatile')
1588
+ if self.const:
1589
+ res.append(' const')
1590
+ if self.refQual:
1591
+ res.append(' ')
1592
+ res.append(self.refQual)
1593
+ if self.exceptionSpec:
1594
+ res.append(' ')
1595
+ res.append(transform(self.exceptionSpec))
1596
+ if self.trailingReturn:
1597
+ res.append(' -> ')
1598
+ res.append(transform(self.trailingReturn))
1599
+ if self.final:
1600
+ res.append(' final')
1601
+ if self.override:
1602
+ res.append(' override')
1603
+ if len(self.attrs) != 0:
1604
+ res.append(' ')
1605
+ res.append(transform(self.attrs))
1606
+ if self.initializer:
1607
+ res.append(' = ')
1608
+ res.append(self.initializer)
1609
+ return ''.join(res)
1610
+
1611
+ def describe_signature(self, signode: TextElement, mode: str,
1612
+ env: BuildEnvironment, symbol: Symbol) -> None:
1613
+ verify_description_mode(mode)
1614
+ multi_line_parameter_list = False
1615
+ test_node: Element = signode
1616
+ while test_node.parent:
1617
+ if not isinstance(test_node, addnodes.desc_signature):
1618
+ test_node = test_node.parent
1619
+ continue
1620
+ multi_line_parameter_list = test_node.get('multi_line_parameter_list', False)
1621
+ break
1622
+
1623
+ # only use the desc_parameterlist for the outer list, not for inner lists
1624
+ if mode == 'lastIsName':
1625
+ paramlist = addnodes.desc_parameterlist()
1626
+ paramlist['multi_line_parameter_list'] = multi_line_parameter_list
1627
+ for arg in self.args:
1628
+ param = addnodes.desc_parameter('', '', noemph=True)
1629
+ arg.describe_signature(param, 'param', env, symbol=symbol)
1630
+ paramlist += param
1631
+ signode += paramlist
1632
+ else:
1633
+ signode += addnodes.desc_sig_punctuation('(', '(')
1634
+ first = True
1635
+ for arg in self.args:
1636
+ if not first:
1637
+ signode += addnodes.desc_sig_punctuation(',', ',')
1638
+ signode += addnodes.desc_sig_space()
1639
+ first = False
1640
+ arg.describe_signature(signode, 'markType', env, symbol=symbol)
1641
+ signode += addnodes.desc_sig_punctuation(')', ')')
1642
+
1643
+ def _add_anno(signode: TextElement, text: str) -> None:
1644
+ signode += addnodes.desc_sig_space()
1645
+ signode += addnodes.desc_sig_keyword(text, text)
1646
+
1647
+ if self.volatile:
1648
+ _add_anno(signode, 'volatile')
1649
+ if self.const:
1650
+ _add_anno(signode, 'const')
1651
+ if self.refQual:
1652
+ signode += addnodes.desc_sig_space()
1653
+ signode += addnodes.desc_sig_punctuation(self.refQual, self.refQual)
1654
+ if self.exceptionSpec:
1655
+ signode += addnodes.desc_sig_space()
1656
+ self.exceptionSpec.describe_signature(signode, mode, env, symbol)
1657
+ if self.trailingReturn:
1658
+ signode += addnodes.desc_sig_space()
1659
+ signode += addnodes.desc_sig_operator('->', '->')
1660
+ signode += addnodes.desc_sig_space()
1661
+ self.trailingReturn.describe_signature(signode, mode, env, symbol)
1662
+ if self.final:
1663
+ _add_anno(signode, 'final')
1664
+ if self.override:
1665
+ _add_anno(signode, 'override')
1666
+ if len(self.attrs) != 0:
1667
+ signode += addnodes.desc_sig_space()
1668
+ self.attrs.describe_signature(signode)
1669
+ if self.initializer:
1670
+ signode += addnodes.desc_sig_space()
1671
+ signode += addnodes.desc_sig_punctuation('=', '=')
1672
+ signode += addnodes.desc_sig_space()
1673
+ assert self.initializer in ('0', 'delete', 'default')
1674
+ if self.initializer == '0':
1675
+ signode += addnodes.desc_sig_literal_number('0', '0')
1676
+ else:
1677
+ signode += addnodes.desc_sig_keyword(self.initializer, self.initializer)
1678
+
1679
+
1680
+ class ASTExplicitSpec(ASTBase):
1681
+ def __init__(self, expr: ASTExpression | None) -> None:
1682
+ self.expr = expr
1683
+
1684
+ def _stringify(self, transform: StringifyTransform) -> str:
1685
+ res = ['explicit']
1686
+ if self.expr is not None:
1687
+ res.append('(')
1688
+ res.append(transform(self.expr))
1689
+ res.append(')')
1690
+ return ''.join(res)
1691
+
1692
+ def describe_signature(self, signode: TextElement,
1693
+ env: BuildEnvironment, symbol: Symbol) -> None:
1694
+ signode += addnodes.desc_sig_keyword('explicit', 'explicit')
1695
+ if self.expr is not None:
1696
+ signode += addnodes.desc_sig_punctuation('(', '(')
1697
+ self.expr.describe_signature(signode, 'markType', env, symbol)
1698
+ signode += addnodes.desc_sig_punctuation(')', ')')
1699
+
1700
+
1701
+ class ASTDeclSpecsSimple(ASTBase):
1702
+ def __init__(self, storage: str, threadLocal: bool, inline: bool, virtual: bool,
1703
+ explicitSpec: ASTExplicitSpec | None,
1704
+ consteval: bool, constexpr: bool, constinit: bool,
1705
+ volatile: bool, const: bool, friend: bool,
1706
+ attrs: ASTAttributeList) -> None:
1707
+ self.storage = storage
1708
+ self.threadLocal = threadLocal
1709
+ self.inline = inline
1710
+ self.virtual = virtual
1711
+ self.explicitSpec = explicitSpec
1712
+ self.consteval = consteval
1713
+ self.constexpr = constexpr
1714
+ self.constinit = constinit
1715
+ self.volatile = volatile
1716
+ self.const = const
1717
+ self.friend = friend
1718
+ self.attrs = attrs
1719
+
1720
+ def mergeWith(self, other: ASTDeclSpecsSimple) -> ASTDeclSpecsSimple:
1721
+ if not other:
1722
+ return self
1723
+ return ASTDeclSpecsSimple(self.storage or other.storage,
1724
+ self.threadLocal or other.threadLocal,
1725
+ self.inline or other.inline,
1726
+ self.virtual or other.virtual,
1727
+ self.explicitSpec or other.explicitSpec,
1728
+ self.consteval or other.consteval,
1729
+ self.constexpr or other.constexpr,
1730
+ self.constinit or other.constinit,
1731
+ self.volatile or other.volatile,
1732
+ self.const or other.const,
1733
+ self.friend or other.friend,
1734
+ self.attrs + other.attrs)
1735
+
1736
+ def _stringify(self, transform: StringifyTransform) -> str:
1737
+ res: list[str] = []
1738
+ if len(self.attrs) != 0:
1739
+ res.append(transform(self.attrs))
1740
+ if self.storage:
1741
+ res.append(self.storage)
1742
+ if self.threadLocal:
1743
+ res.append('thread_local')
1744
+ if self.inline:
1745
+ res.append('inline')
1746
+ if self.friend:
1747
+ res.append('friend')
1748
+ if self.virtual:
1749
+ res.append('virtual')
1750
+ if self.explicitSpec:
1751
+ res.append(transform(self.explicitSpec))
1752
+ if self.consteval:
1753
+ res.append('consteval')
1754
+ if self.constexpr:
1755
+ res.append('constexpr')
1756
+ if self.constinit:
1757
+ res.append('constinit')
1758
+ if self.volatile:
1759
+ res.append('volatile')
1760
+ if self.const:
1761
+ res.append('const')
1762
+ return ' '.join(res)
1763
+
1764
+ def describe_signature(self, signode: TextElement,
1765
+ env: BuildEnvironment, symbol: Symbol) -> None:
1766
+ self.attrs.describe_signature(signode)
1767
+ addSpace = len(self.attrs) != 0
1768
+
1769
+ def _add(signode: TextElement, text: str) -> bool:
1770
+ if addSpace:
1771
+ signode += addnodes.desc_sig_space()
1772
+ signode += addnodes.desc_sig_keyword(text, text)
1773
+ return True
1774
+
1775
+ if self.storage:
1776
+ addSpace = _add(signode, self.storage)
1777
+ if self.threadLocal:
1778
+ addSpace = _add(signode, 'thread_local')
1779
+ if self.inline:
1780
+ addSpace = _add(signode, 'inline')
1781
+ if self.friend:
1782
+ addSpace = _add(signode, 'friend')
1783
+ if self.virtual:
1784
+ addSpace = _add(signode, 'virtual')
1785
+ if self.explicitSpec:
1786
+ if addSpace:
1787
+ signode += addnodes.desc_sig_space()
1788
+ self.explicitSpec.describe_signature(signode, env, symbol)
1789
+ addSpace = True
1790
+ if self.consteval:
1791
+ addSpace = _add(signode, 'consteval')
1792
+ if self.constexpr:
1793
+ addSpace = _add(signode, 'constexpr')
1794
+ if self.constinit:
1795
+ addSpace = _add(signode, 'constinit')
1796
+ if self.volatile:
1797
+ addSpace = _add(signode, 'volatile')
1798
+ if self.const:
1799
+ addSpace = _add(signode, 'const')
1800
+
1801
+
1802
+ class ASTDeclSpecs(ASTBase):
1803
+ def __init__(self, outer: str,
1804
+ leftSpecs: ASTDeclSpecsSimple, rightSpecs: ASTDeclSpecsSimple,
1805
+ trailing: ASTTrailingTypeSpec) -> None:
1806
+ # leftSpecs and rightSpecs are used for output
1807
+ # allSpecs are used for id generation
1808
+ self.outer = outer
1809
+ self.leftSpecs = leftSpecs
1810
+ self.rightSpecs = rightSpecs
1811
+ self.allSpecs = self.leftSpecs.mergeWith(self.rightSpecs)
1812
+ self.trailingTypeSpec = trailing
1813
+
1814
+ def get_id(self, version: int) -> str:
1815
+ if version == 1:
1816
+ res = []
1817
+ res.append(self.trailingTypeSpec.get_id(version))
1818
+ if self.allSpecs.volatile:
1819
+ res.append('V')
1820
+ if self.allSpecs.const:
1821
+ res.append('C')
1822
+ return ''.join(res)
1823
+ res = []
1824
+ if self.allSpecs.volatile:
1825
+ res.append('V')
1826
+ if self.allSpecs.const:
1827
+ res.append('K')
1828
+ if self.trailingTypeSpec is not None:
1829
+ res.append(self.trailingTypeSpec.get_id(version))
1830
+ return ''.join(res)
1831
+
1832
+ def _stringify(self, transform: StringifyTransform) -> str:
1833
+ res: list[str] = []
1834
+ l = transform(self.leftSpecs)
1835
+ if len(l) > 0:
1836
+ res.append(l)
1837
+ if self.trailingTypeSpec:
1838
+ if len(res) > 0:
1839
+ res.append(" ")
1840
+ res.append(transform(self.trailingTypeSpec))
1841
+ r = str(self.rightSpecs)
1842
+ if len(r) > 0:
1843
+ if len(res) > 0:
1844
+ res.append(" ")
1845
+ res.append(r)
1846
+ return "".join(res)
1847
+
1848
+ def describe_signature(self, signode: TextElement, mode: str,
1849
+ env: BuildEnvironment, symbol: Symbol) -> None:
1850
+ verify_description_mode(mode)
1851
+ numChildren = len(signode)
1852
+ self.leftSpecs.describe_signature(signode, env, symbol)
1853
+ addSpace = len(signode) != numChildren
1854
+
1855
+ if self.trailingTypeSpec:
1856
+ if addSpace:
1857
+ signode += addnodes.desc_sig_space()
1858
+ numChildren = len(signode)
1859
+ self.trailingTypeSpec.describe_signature(signode, mode, env,
1860
+ symbol=symbol)
1861
+ addSpace = len(signode) != numChildren
1862
+
1863
+ if len(str(self.rightSpecs)) > 0:
1864
+ if addSpace:
1865
+ signode += addnodes.desc_sig_space()
1866
+ self.rightSpecs.describe_signature(signode, env, symbol)
1867
+
1868
+
1869
+ # Declarator
1870
+ ################################################################################
1871
+
1872
+ class ASTArray(ASTBase):
1873
+ def __init__(self, size: ASTExpression) -> None:
1874
+ self.size = size
1875
+
1876
+ def _stringify(self, transform: StringifyTransform) -> str:
1877
+ if self.size:
1878
+ return '[' + transform(self.size) + ']'
1879
+ else:
1880
+ return '[]'
1881
+
1882
+ def get_id(self, version: int) -> str:
1883
+ if version == 1:
1884
+ return 'A'
1885
+ if version == 2:
1886
+ if self.size:
1887
+ return 'A' + str(self.size) + '_'
1888
+ else:
1889
+ return 'A_'
1890
+ if self.size:
1891
+ return 'A' + self.size.get_id(version) + '_'
1892
+ else:
1893
+ return 'A_'
1894
+
1895
+ def describe_signature(self, signode: TextElement, mode: str,
1896
+ env: BuildEnvironment, symbol: Symbol) -> None:
1897
+ verify_description_mode(mode)
1898
+ signode += addnodes.desc_sig_punctuation('[', '[')
1899
+ if self.size:
1900
+ self.size.describe_signature(signode, 'markType', env, symbol)
1901
+ signode += addnodes.desc_sig_punctuation(']', ']')
1902
+
1903
+
1904
+ class ASTDeclarator(ASTBase):
1905
+ @property
1906
+ def name(self) -> ASTNestedName:
1907
+ raise NotImplementedError(repr(self))
1908
+
1909
+ @name.setter
1910
+ def name(self, name: ASTNestedName) -> None:
1911
+ raise NotImplementedError(repr(self))
1912
+
1913
+ @property
1914
+ def isPack(self) -> bool:
1915
+ raise NotImplementedError(repr(self))
1916
+
1917
+ @property
1918
+ def function_params(self) -> list[ASTFunctionParameter]:
1919
+ raise NotImplementedError(repr(self))
1920
+
1921
+ @property
1922
+ def trailingReturn(self) -> ASTType:
1923
+ raise NotImplementedError(repr(self))
1924
+
1925
+ def require_space_after_declSpecs(self) -> bool:
1926
+ raise NotImplementedError(repr(self))
1927
+
1928
+ def get_modifiers_id(self, version: int) -> str:
1929
+ raise NotImplementedError(repr(self))
1930
+
1931
+ def get_param_id(self, version: int) -> str:
1932
+ raise NotImplementedError(repr(self))
1933
+
1934
+ def get_ptr_suffix_id(self, version: int) -> str:
1935
+ raise NotImplementedError(repr(self))
1936
+
1937
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
1938
+ raise NotImplementedError(repr(self))
1939
+
1940
+ def is_function_type(self) -> bool:
1941
+ raise NotImplementedError(repr(self))
1942
+
1943
+ def describe_signature(self, signode: TextElement, mode: str,
1944
+ env: BuildEnvironment, symbol: Symbol) -> None:
1945
+ raise NotImplementedError(repr(self))
1946
+
1947
+
1948
+ class ASTDeclaratorNameParamQual(ASTDeclarator):
1949
+ def __init__(self, declId: ASTNestedName,
1950
+ arrayOps: list[ASTArray],
1951
+ paramQual: ASTParametersQualifiers) -> None:
1952
+ self.declId = declId
1953
+ self.arrayOps = arrayOps
1954
+ self.paramQual = paramQual
1955
+
1956
+ @property
1957
+ def name(self) -> ASTNestedName:
1958
+ return self.declId
1959
+
1960
+ @name.setter
1961
+ def name(self, name: ASTNestedName) -> None:
1962
+ self.declId = name
1963
+
1964
+ @property
1965
+ def isPack(self) -> bool:
1966
+ return False
1967
+
1968
+ @property
1969
+ def function_params(self) -> list[ASTFunctionParameter]:
1970
+ return self.paramQual.function_params
1971
+
1972
+ @property
1973
+ def trailingReturn(self) -> ASTType:
1974
+ return self.paramQual.trailingReturn
1975
+
1976
+ # only the modifiers for a function, e.g.,
1977
+ def get_modifiers_id(self, version: int) -> str:
1978
+ # cv-qualifiers
1979
+ if self.paramQual:
1980
+ return self.paramQual.get_modifiers_id(version)
1981
+ raise Exception("This should only be called on a function: %s" % self)
1982
+
1983
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
1984
+ if self.paramQual:
1985
+ return self.paramQual.get_param_id(version)
1986
+ else:
1987
+ return ''
1988
+
1989
+ def get_ptr_suffix_id(self, version: int) -> str: # only the array specifiers
1990
+ return ''.join(a.get_id(version) for a in self.arrayOps)
1991
+
1992
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
1993
+ assert version >= 2
1994
+ res = []
1995
+ # TODO: can we actually have both array ops and paramQual?
1996
+ res.append(self.get_ptr_suffix_id(version))
1997
+ if self.paramQual:
1998
+ res.append(self.get_modifiers_id(version))
1999
+ res.append('F')
2000
+ res.append(returnTypeId)
2001
+ res.append(self.get_param_id(version))
2002
+ res.append('E')
2003
+ else:
2004
+ res.append(returnTypeId)
2005
+ return ''.join(res)
2006
+
2007
+ # ------------------------------------------------------------------------
2008
+
2009
+ def require_space_after_declSpecs(self) -> bool:
2010
+ return self.declId is not None
2011
+
2012
+ def is_function_type(self) -> bool:
2013
+ return self.paramQual is not None
2014
+
2015
+ def _stringify(self, transform: StringifyTransform) -> str:
2016
+ res = []
2017
+ if self.declId:
2018
+ res.append(transform(self.declId))
2019
+ res.extend(transform(op) for op in self.arrayOps)
2020
+ if self.paramQual:
2021
+ res.append(transform(self.paramQual))
2022
+ return ''.join(res)
2023
+
2024
+ def describe_signature(self, signode: TextElement, mode: str,
2025
+ env: BuildEnvironment, symbol: Symbol) -> None:
2026
+ verify_description_mode(mode)
2027
+ if self.declId:
2028
+ self.declId.describe_signature(signode, mode, env, symbol)
2029
+ for op in self.arrayOps:
2030
+ op.describe_signature(signode, mode, env, symbol)
2031
+ if self.paramQual:
2032
+ self.paramQual.describe_signature(signode, mode, env, symbol)
2033
+
2034
+
2035
+ class ASTDeclaratorNameBitField(ASTDeclarator):
2036
+ def __init__(self, declId: ASTNestedName, size: ASTExpression) -> None:
2037
+ self.declId = declId
2038
+ self.size = size
2039
+
2040
+ @property
2041
+ def name(self) -> ASTNestedName:
2042
+ return self.declId
2043
+
2044
+ @name.setter
2045
+ def name(self, name: ASTNestedName) -> None:
2046
+ self.declId = name
2047
+
2048
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
2049
+ return ''
2050
+
2051
+ def get_ptr_suffix_id(self, version: int) -> str: # only the array specifiers
2052
+ return ''
2053
+
2054
+ # ------------------------------------------------------------------------
2055
+
2056
+ def require_space_after_declSpecs(self) -> bool:
2057
+ return self.declId is not None
2058
+
2059
+ def is_function_type(self) -> bool:
2060
+ return False
2061
+
2062
+ def _stringify(self, transform: StringifyTransform) -> str:
2063
+ res = []
2064
+ if self.declId:
2065
+ res.append(transform(self.declId))
2066
+ res.append(" : ")
2067
+ res.append(transform(self.size))
2068
+ return ''.join(res)
2069
+
2070
+ def describe_signature(self, signode: TextElement, mode: str,
2071
+ env: BuildEnvironment, symbol: Symbol) -> None:
2072
+ verify_description_mode(mode)
2073
+ if self.declId:
2074
+ self.declId.describe_signature(signode, mode, env, symbol)
2075
+ signode += addnodes.desc_sig_space()
2076
+ signode += addnodes.desc_sig_punctuation(':', ':')
2077
+ signode += addnodes.desc_sig_space()
2078
+ self.size.describe_signature(signode, mode, env, symbol)
2079
+
2080
+
2081
+ class ASTDeclaratorPtr(ASTDeclarator):
2082
+ def __init__(self, next: ASTDeclarator, volatile: bool, const: bool,
2083
+ attrs: ASTAttributeList) -> None:
2084
+ assert next
2085
+ self.next = next
2086
+ self.volatile = volatile
2087
+ self.const = const
2088
+ self.attrs = attrs
2089
+
2090
+ @property
2091
+ def name(self) -> ASTNestedName:
2092
+ return self.next.name
2093
+
2094
+ @name.setter
2095
+ def name(self, name: ASTNestedName) -> None:
2096
+ self.next.name = name
2097
+
2098
+ @property
2099
+ def isPack(self) -> bool:
2100
+ return self.next.isPack
2101
+
2102
+ @property
2103
+ def function_params(self) -> list[ASTFunctionParameter]:
2104
+ return self.next.function_params
2105
+
2106
+ @property
2107
+ def trailingReturn(self) -> ASTType:
2108
+ return self.next.trailingReturn
2109
+
2110
+ def require_space_after_declSpecs(self) -> bool:
2111
+ return self.next.require_space_after_declSpecs()
2112
+
2113
+ def _stringify(self, transform: StringifyTransform) -> str:
2114
+ res = ['*']
2115
+ res.append(transform(self.attrs))
2116
+ if len(self.attrs) != 0 and (self.volatile or self.const):
2117
+ res.append(' ')
2118
+ if self.volatile:
2119
+ res.append('volatile')
2120
+ if self.const:
2121
+ if self.volatile:
2122
+ res.append(' ')
2123
+ res.append('const')
2124
+ if self.const or self.volatile or len(self.attrs) > 0:
2125
+ if self.next.require_space_after_declSpecs():
2126
+ res.append(' ')
2127
+ res.append(transform(self.next))
2128
+ return ''.join(res)
2129
+
2130
+ def get_modifiers_id(self, version: int) -> str:
2131
+ return self.next.get_modifiers_id(version)
2132
+
2133
+ def get_param_id(self, version: int) -> str:
2134
+ return self.next.get_param_id(version)
2135
+
2136
+ def get_ptr_suffix_id(self, version: int) -> str:
2137
+ if version == 1:
2138
+ res = ['P']
2139
+ if self.volatile:
2140
+ res.append('V')
2141
+ if self.const:
2142
+ res.append('C')
2143
+ res.append(self.next.get_ptr_suffix_id(version))
2144
+ return ''.join(res)
2145
+
2146
+ res = [self.next.get_ptr_suffix_id(version)]
2147
+ res.append('P')
2148
+ if self.volatile:
2149
+ res.append('V')
2150
+ if self.const:
2151
+ res.append('C')
2152
+ return ''.join(res)
2153
+
2154
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
2155
+ # ReturnType *next, so we are part of the return type of 'next
2156
+ res = ['P']
2157
+ if self.volatile:
2158
+ res.append('V')
2159
+ if self.const:
2160
+ res.append('C')
2161
+ res.append(returnTypeId)
2162
+ return self.next.get_type_id(version, returnTypeId=''.join(res))
2163
+
2164
+ def is_function_type(self) -> bool:
2165
+ return self.next.is_function_type()
2166
+
2167
+ def describe_signature(self, signode: TextElement, mode: str,
2168
+ env: BuildEnvironment, symbol: Symbol) -> None:
2169
+ verify_description_mode(mode)
2170
+ signode += addnodes.desc_sig_punctuation('*', '*')
2171
+ self.attrs.describe_signature(signode)
2172
+ if len(self.attrs) != 0 and (self.volatile or self.const):
2173
+ signode += addnodes.desc_sig_space()
2174
+
2175
+ def _add_anno(signode: TextElement, text: str) -> None:
2176
+ signode += addnodes.desc_sig_keyword(text, text)
2177
+ if self.volatile:
2178
+ _add_anno(signode, 'volatile')
2179
+ if self.const:
2180
+ if self.volatile:
2181
+ signode += addnodes.desc_sig_space()
2182
+ _add_anno(signode, 'const')
2183
+ if self.const or self.volatile or len(self.attrs) > 0:
2184
+ if self.next.require_space_after_declSpecs():
2185
+ signode += addnodes.desc_sig_space()
2186
+ self.next.describe_signature(signode, mode, env, symbol)
2187
+
2188
+
2189
+ class ASTDeclaratorRef(ASTDeclarator):
2190
+ def __init__(self, next: ASTDeclarator, attrs: ASTAttributeList) -> None:
2191
+ assert next
2192
+ self.next = next
2193
+ self.attrs = attrs
2194
+
2195
+ @property
2196
+ def name(self) -> ASTNestedName:
2197
+ return self.next.name
2198
+
2199
+ @name.setter
2200
+ def name(self, name: ASTNestedName) -> None:
2201
+ self.next.name = name
2202
+
2203
+ @property
2204
+ def isPack(self) -> bool:
2205
+ return self.next.isPack
2206
+
2207
+ @property
2208
+ def function_params(self) -> list[ASTFunctionParameter]:
2209
+ return self.next.function_params
2210
+
2211
+ @property
2212
+ def trailingReturn(self) -> ASTType:
2213
+ return self.next.trailingReturn
2214
+
2215
+ def require_space_after_declSpecs(self) -> bool:
2216
+ return self.next.require_space_after_declSpecs()
2217
+
2218
+ def _stringify(self, transform: StringifyTransform) -> str:
2219
+ res = ['&']
2220
+ res.append(transform(self.attrs))
2221
+ if len(self.attrs) != 0 and self.next.require_space_after_declSpecs():
2222
+ res.append(' ')
2223
+ res.append(transform(self.next))
2224
+ return ''.join(res)
2225
+
2226
+ def get_modifiers_id(self, version: int) -> str:
2227
+ return self.next.get_modifiers_id(version)
2228
+
2229
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
2230
+ return self.next.get_param_id(version)
2231
+
2232
+ def get_ptr_suffix_id(self, version: int) -> str:
2233
+ if version == 1:
2234
+ return 'R' + self.next.get_ptr_suffix_id(version)
2235
+ else:
2236
+ return self.next.get_ptr_suffix_id(version) + 'R'
2237
+
2238
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
2239
+ assert version >= 2
2240
+ # ReturnType &next, so we are part of the return type of 'next
2241
+ return self.next.get_type_id(version, returnTypeId='R' + returnTypeId)
2242
+
2243
+ def is_function_type(self) -> bool:
2244
+ return self.next.is_function_type()
2245
+
2246
+ def describe_signature(self, signode: TextElement, mode: str,
2247
+ env: BuildEnvironment, symbol: Symbol) -> None:
2248
+ verify_description_mode(mode)
2249
+ signode += addnodes.desc_sig_punctuation('&', '&')
2250
+ self.attrs.describe_signature(signode)
2251
+ if len(self.attrs) > 0 and self.next.require_space_after_declSpecs():
2252
+ signode += addnodes.desc_sig_space()
2253
+ self.next.describe_signature(signode, mode, env, symbol)
2254
+
2255
+
2256
+ class ASTDeclaratorParamPack(ASTDeclarator):
2257
+ def __init__(self, next: ASTDeclarator) -> None:
2258
+ assert next
2259
+ self.next = next
2260
+
2261
+ @property
2262
+ def name(self) -> ASTNestedName:
2263
+ return self.next.name
2264
+
2265
+ @name.setter
2266
+ def name(self, name: ASTNestedName) -> None:
2267
+ self.next.name = name
2268
+
2269
+ @property
2270
+ def function_params(self) -> list[ASTFunctionParameter]:
2271
+ return self.next.function_params
2272
+
2273
+ @property
2274
+ def trailingReturn(self) -> ASTType:
2275
+ return self.next.trailingReturn
2276
+
2277
+ @property
2278
+ def isPack(self) -> bool:
2279
+ return True
2280
+
2281
+ def require_space_after_declSpecs(self) -> bool:
2282
+ return False
2283
+
2284
+ def _stringify(self, transform: StringifyTransform) -> str:
2285
+ res = transform(self.next)
2286
+ if self.next.name:
2287
+ res = ' ' + res
2288
+ return '...' + res
2289
+
2290
+ def get_modifiers_id(self, version: int) -> str:
2291
+ return self.next.get_modifiers_id(version)
2292
+
2293
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
2294
+ return self.next.get_param_id(version)
2295
+
2296
+ def get_ptr_suffix_id(self, version: int) -> str:
2297
+ if version == 1:
2298
+ return 'Dp' + self.next.get_ptr_suffix_id(version)
2299
+ else:
2300
+ return self.next.get_ptr_suffix_id(version) + 'Dp'
2301
+
2302
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
2303
+ assert version >= 2
2304
+ # ReturnType... next, so we are part of the return type of 'next
2305
+ return self.next.get_type_id(version, returnTypeId='Dp' + returnTypeId)
2306
+
2307
+ def is_function_type(self) -> bool:
2308
+ return self.next.is_function_type()
2309
+
2310
+ def describe_signature(self, signode: TextElement, mode: str,
2311
+ env: BuildEnvironment, symbol: Symbol) -> None:
2312
+ verify_description_mode(mode)
2313
+ signode += addnodes.desc_sig_punctuation('...', '...')
2314
+ if self.next.name:
2315
+ signode += addnodes.desc_sig_space()
2316
+ self.next.describe_signature(signode, mode, env, symbol)
2317
+
2318
+
2319
+ class ASTDeclaratorMemPtr(ASTDeclarator):
2320
+ def __init__(self, className: ASTNestedName,
2321
+ const: bool, volatile: bool, next: ASTDeclarator) -> None:
2322
+ assert className
2323
+ assert next
2324
+ self.className = className
2325
+ self.const = const
2326
+ self.volatile = volatile
2327
+ self.next = next
2328
+
2329
+ @property
2330
+ def name(self) -> ASTNestedName:
2331
+ return self.next.name
2332
+
2333
+ @name.setter
2334
+ def name(self, name: ASTNestedName) -> None:
2335
+ self.next.name = name
2336
+
2337
+ @property
2338
+ def isPack(self) -> bool:
2339
+ return self.next.isPack
2340
+
2341
+ @property
2342
+ def function_params(self) -> list[ASTFunctionParameter]:
2343
+ return self.next.function_params
2344
+
2345
+ @property
2346
+ def trailingReturn(self) -> ASTType:
2347
+ return self.next.trailingReturn
2348
+
2349
+ def require_space_after_declSpecs(self) -> bool:
2350
+ return True
2351
+
2352
+ def _stringify(self, transform: StringifyTransform) -> str:
2353
+ res = []
2354
+ res.append(transform(self.className))
2355
+ res.append('::*')
2356
+ if self.volatile:
2357
+ res.append('volatile')
2358
+ if self.const:
2359
+ if self.volatile:
2360
+ res.append(' ')
2361
+ res.append('const')
2362
+ if self.next.require_space_after_declSpecs():
2363
+ res.append(' ')
2364
+ res.append(transform(self.next))
2365
+ return ''.join(res)
2366
+
2367
+ def get_modifiers_id(self, version: int) -> str:
2368
+ if version == 1:
2369
+ raise NoOldIdError
2370
+ return self.next.get_modifiers_id(version)
2371
+
2372
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
2373
+ if version == 1:
2374
+ raise NoOldIdError
2375
+ return self.next.get_param_id(version)
2376
+
2377
+ def get_ptr_suffix_id(self, version: int) -> str:
2378
+ if version == 1:
2379
+ raise NoOldIdError
2380
+ raise NotImplementedError
2381
+ return self.next.get_ptr_suffix_id(version) + 'Dp'
2382
+
2383
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
2384
+ assert version >= 2
2385
+ # ReturnType name::* next, so we are part of the return type of next
2386
+ nextReturnTypeId = ''
2387
+ if self.volatile:
2388
+ nextReturnTypeId += 'V'
2389
+ if self.const:
2390
+ nextReturnTypeId += 'K'
2391
+ nextReturnTypeId += 'M'
2392
+ nextReturnTypeId += self.className.get_id(version)
2393
+ nextReturnTypeId += returnTypeId
2394
+ return self.next.get_type_id(version, nextReturnTypeId)
2395
+
2396
+ def is_function_type(self) -> bool:
2397
+ return self.next.is_function_type()
2398
+
2399
+ def describe_signature(self, signode: TextElement, mode: str,
2400
+ env: BuildEnvironment, symbol: Symbol) -> None:
2401
+ verify_description_mode(mode)
2402
+ self.className.describe_signature(signode, 'markType', env, symbol)
2403
+ signode += addnodes.desc_sig_punctuation('::', '::')
2404
+ signode += addnodes.desc_sig_punctuation('*', '*')
2405
+
2406
+ def _add_anno(signode: TextElement, text: str) -> None:
2407
+ signode += addnodes.desc_sig_keyword(text, text)
2408
+ if self.volatile:
2409
+ _add_anno(signode, 'volatile')
2410
+ if self.const:
2411
+ if self.volatile:
2412
+ signode += addnodes.desc_sig_space()
2413
+ _add_anno(signode, 'const')
2414
+ if self.next.require_space_after_declSpecs():
2415
+ signode += addnodes.desc_sig_space()
2416
+ self.next.describe_signature(signode, mode, env, symbol)
2417
+
2418
+
2419
+ class ASTDeclaratorParen(ASTDeclarator):
2420
+ def __init__(self, inner: ASTDeclarator, next: ASTDeclarator) -> None:
2421
+ assert inner
2422
+ assert next
2423
+ self.inner = inner
2424
+ self.next = next
2425
+ # TODO: we assume the name, params, and qualifiers are in inner
2426
+
2427
+ @property
2428
+ def name(self) -> ASTNestedName:
2429
+ return self.inner.name
2430
+
2431
+ @name.setter
2432
+ def name(self, name: ASTNestedName) -> None:
2433
+ self.inner.name = name
2434
+
2435
+ @property
2436
+ def isPack(self) -> bool:
2437
+ return self.inner.isPack or self.next.isPack
2438
+
2439
+ @property
2440
+ def function_params(self) -> list[ASTFunctionParameter]:
2441
+ return self.inner.function_params
2442
+
2443
+ @property
2444
+ def trailingReturn(self) -> ASTType:
2445
+ return self.inner.trailingReturn
2446
+
2447
+ def require_space_after_declSpecs(self) -> bool:
2448
+ return True
2449
+
2450
+ def _stringify(self, transform: StringifyTransform) -> str:
2451
+ res = ['(']
2452
+ res.append(transform(self.inner))
2453
+ res.append(')')
2454
+ res.append(transform(self.next))
2455
+ return ''.join(res)
2456
+
2457
+ def get_modifiers_id(self, version: int) -> str:
2458
+ return self.inner.get_modifiers_id(version)
2459
+
2460
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
2461
+ return self.inner.get_param_id(version)
2462
+
2463
+ def get_ptr_suffix_id(self, version: int) -> str:
2464
+ if version == 1:
2465
+ raise NoOldIdError # TODO: was this implemented before?
2466
+ return self.next.get_ptr_suffix_id(version) + \
2467
+ self.inner.get_ptr_suffix_id(version)
2468
+ return self.inner.get_ptr_suffix_id(version) + \
2469
+ self.next.get_ptr_suffix_id(version)
2470
+
2471
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
2472
+ assert version >= 2
2473
+ # ReturnType (inner)next, so 'inner' returns everything outside
2474
+ nextId = self.next.get_type_id(version, returnTypeId)
2475
+ return self.inner.get_type_id(version, returnTypeId=nextId)
2476
+
2477
+ def is_function_type(self) -> bool:
2478
+ return self.inner.is_function_type()
2479
+
2480
+ def describe_signature(self, signode: TextElement, mode: str,
2481
+ env: BuildEnvironment, symbol: Symbol) -> None:
2482
+ verify_description_mode(mode)
2483
+ signode += addnodes.desc_sig_punctuation('(', '(')
2484
+ self.inner.describe_signature(signode, mode, env, symbol)
2485
+ signode += addnodes.desc_sig_punctuation(')', ')')
2486
+ self.next.describe_signature(signode, "noneIsName", env, symbol)
2487
+
2488
+
2489
+ # Type and initializer stuff
2490
+ ##############################################################################################
2491
+
2492
+ class ASTPackExpansionExpr(ASTExpression):
2493
+ def __init__(self, expr: ASTExpression | ASTBracedInitList) -> None:
2494
+ self.expr = expr
2495
+
2496
+ def _stringify(self, transform: StringifyTransform) -> str:
2497
+ return transform(self.expr) + '...'
2498
+
2499
+ def get_id(self, version: int) -> str:
2500
+ id = self.expr.get_id(version)
2501
+ return 'sp' + id
2502
+
2503
+ def describe_signature(self, signode: TextElement, mode: str,
2504
+ env: BuildEnvironment, symbol: Symbol) -> None:
2505
+ self.expr.describe_signature(signode, mode, env, symbol)
2506
+ signode += addnodes.desc_sig_punctuation('...', '...')
2507
+
2508
+
2509
+ class ASTParenExprList(ASTBaseParenExprList):
2510
+ def __init__(self, exprs: list[ASTExpression | ASTBracedInitList]) -> None:
2511
+ self.exprs = exprs
2512
+
2513
+ def get_id(self, version: int) -> str:
2514
+ return "pi%sE" % ''.join(e.get_id(version) for e in self.exprs)
2515
+
2516
+ def _stringify(self, transform: StringifyTransform) -> str:
2517
+ exprs = [transform(e) for e in self.exprs]
2518
+ return '(%s)' % ', '.join(exprs)
2519
+
2520
+ def describe_signature(self, signode: TextElement, mode: str,
2521
+ env: BuildEnvironment, symbol: Symbol) -> None:
2522
+ verify_description_mode(mode)
2523
+ signode += addnodes.desc_sig_punctuation('(', '(')
2524
+ first = True
2525
+ for e in self.exprs:
2526
+ if not first:
2527
+ signode += addnodes.desc_sig_punctuation(',', ',')
2528
+ signode += addnodes.desc_sig_space()
2529
+ else:
2530
+ first = False
2531
+ e.describe_signature(signode, mode, env, symbol)
2532
+ signode += addnodes.desc_sig_punctuation(')', ')')
2533
+
2534
+
2535
+ class ASTInitializer(ASTBase):
2536
+ def __init__(self, value: ASTExpression | ASTBracedInitList,
2537
+ hasAssign: bool = True) -> None:
2538
+ self.value = value
2539
+ self.hasAssign = hasAssign
2540
+
2541
+ def _stringify(self, transform: StringifyTransform) -> str:
2542
+ val = transform(self.value)
2543
+ if self.hasAssign:
2544
+ return ' = ' + val
2545
+ else:
2546
+ return val
2547
+
2548
+ def describe_signature(self, signode: TextElement, mode: str,
2549
+ env: BuildEnvironment, symbol: Symbol) -> None:
2550
+ verify_description_mode(mode)
2551
+ if self.hasAssign:
2552
+ signode += addnodes.desc_sig_space()
2553
+ signode += addnodes.desc_sig_punctuation('=', '=')
2554
+ signode += addnodes.desc_sig_space()
2555
+ self.value.describe_signature(signode, 'markType', env, symbol)
2556
+
2557
+
2558
+ class ASTType(ASTBase):
2559
+ def __init__(self, declSpecs: ASTDeclSpecs, decl: ASTDeclarator) -> None:
2560
+ assert declSpecs
2561
+ assert decl
2562
+ self.declSpecs = declSpecs
2563
+ self.decl = decl
2564
+
2565
+ @property
2566
+ def name(self) -> ASTNestedName:
2567
+ return self.decl.name
2568
+
2569
+ @name.setter
2570
+ def name(self, name: ASTNestedName) -> None:
2571
+ self.decl.name = name
2572
+
2573
+ @property
2574
+ def isPack(self) -> bool:
2575
+ return self.decl.isPack
2576
+
2577
+ @property
2578
+ def function_params(self) -> list[ASTFunctionParameter]:
2579
+ return self.decl.function_params
2580
+
2581
+ @property
2582
+ def trailingReturn(self) -> ASTType:
2583
+ return self.decl.trailingReturn
2584
+
2585
+ def get_id(self, version: int, objectType: str | None = None,
2586
+ symbol: Symbol | None = None) -> str:
2587
+ if version == 1:
2588
+ res = []
2589
+ if objectType: # needs the name
2590
+ if objectType == 'function': # also modifiers
2591
+ res.append(symbol.get_full_nested_name().get_id(version))
2592
+ res.append(self.decl.get_param_id(version))
2593
+ res.append(self.decl.get_modifiers_id(version))
2594
+ if (self.declSpecs.leftSpecs.constexpr or
2595
+ (self.declSpecs.rightSpecs and
2596
+ self.declSpecs.rightSpecs.constexpr)):
2597
+ res.append('CE')
2598
+ elif objectType == 'type': # just the name
2599
+ res.append(symbol.get_full_nested_name().get_id(version))
2600
+ else:
2601
+ raise AssertionError(objectType)
2602
+ else: # only type encoding
2603
+ if self.decl.is_function_type():
2604
+ raise NoOldIdError
2605
+ res.append(self.declSpecs.get_id(version))
2606
+ res.append(self.decl.get_ptr_suffix_id(version))
2607
+ res.append(self.decl.get_param_id(version))
2608
+ return ''.join(res)
2609
+ # other versions
2610
+ res = []
2611
+ if objectType: # needs the name
2612
+ if objectType == 'function': # also modifiers
2613
+ modifiers = self.decl.get_modifiers_id(version)
2614
+ res.append(symbol.get_full_nested_name().get_id(version, modifiers))
2615
+ if version >= 4:
2616
+ # with templates we need to mangle the return type in as well
2617
+ templ = symbol.declaration.templatePrefix
2618
+ if templ is not None:
2619
+ typeId = self.decl.get_ptr_suffix_id(version)
2620
+ if self.trailingReturn:
2621
+ returnTypeId = self.trailingReturn.get_id(version)
2622
+ else:
2623
+ returnTypeId = self.declSpecs.get_id(version)
2624
+ res.append(typeId)
2625
+ res.append(returnTypeId)
2626
+ res.append(self.decl.get_param_id(version))
2627
+ elif objectType == 'type': # just the name
2628
+ res.append(symbol.get_full_nested_name().get_id(version))
2629
+ else:
2630
+ raise AssertionError(objectType)
2631
+ else: # only type encoding
2632
+ # the 'returnType' of a non-function type is simply just the last
2633
+ # type, i.e., for 'int*' it is 'int'
2634
+ returnTypeId = self.declSpecs.get_id(version)
2635
+ typeId = self.decl.get_type_id(version, returnTypeId)
2636
+ res.append(typeId)
2637
+ return ''.join(res)
2638
+
2639
+ def _stringify(self, transform: StringifyTransform) -> str:
2640
+ res = []
2641
+ declSpecs = transform(self.declSpecs)
2642
+ res.append(declSpecs)
2643
+ if self.decl.require_space_after_declSpecs() and len(declSpecs) > 0:
2644
+ res.append(' ')
2645
+ res.append(transform(self.decl))
2646
+ return ''.join(res)
2647
+
2648
+ def get_type_declaration_prefix(self) -> str:
2649
+ if self.declSpecs.trailingTypeSpec:
2650
+ return 'typedef'
2651
+ else:
2652
+ return 'type'
2653
+
2654
+ def describe_signature(self, signode: TextElement, mode: str,
2655
+ env: BuildEnvironment, symbol: Symbol) -> None:
2656
+ verify_description_mode(mode)
2657
+ self.declSpecs.describe_signature(signode, 'markType', env, symbol)
2658
+ if (self.decl.require_space_after_declSpecs() and
2659
+ len(str(self.declSpecs)) > 0):
2660
+ signode += addnodes.desc_sig_space()
2661
+ # for parameters that don't really declare new names we get 'markType',
2662
+ # this should not be propagated, but be 'noneIsName'.
2663
+ if mode == 'markType':
2664
+ mode = 'noneIsName'
2665
+ self.decl.describe_signature(signode, mode, env, symbol)
2666
+
2667
+
2668
+ class ASTTemplateParamConstrainedTypeWithInit(ASTBase):
2669
+ def __init__(self, type: ASTType, init: ASTType) -> None:
2670
+ assert type
2671
+ self.type = type
2672
+ self.init = init
2673
+
2674
+ @property
2675
+ def name(self) -> ASTNestedName:
2676
+ return self.type.name
2677
+
2678
+ @property
2679
+ def isPack(self) -> bool:
2680
+ return self.type.isPack
2681
+
2682
+ def get_id(
2683
+ self, version: int, objectType: str | None = None, symbol: Symbol | None = None,
2684
+ ) -> str:
2685
+ # this is not part of the normal name mangling in C++
2686
+ assert version >= 2
2687
+ if symbol:
2688
+ # the anchor will be our parent
2689
+ return symbol.parent.declaration.get_id(version, prefixed=False)
2690
+ else:
2691
+ return self.type.get_id(version)
2692
+
2693
+ def _stringify(self, transform: StringifyTransform) -> str:
2694
+ res = transform(self.type)
2695
+ if self.init:
2696
+ res += " = "
2697
+ res += transform(self.init)
2698
+ return res
2699
+
2700
+ def describe_signature(self, signode: TextElement, mode: str,
2701
+ env: BuildEnvironment, symbol: Symbol) -> None:
2702
+ self.type.describe_signature(signode, mode, env, symbol)
2703
+ if self.init:
2704
+ signode += addnodes.desc_sig_space()
2705
+ signode += addnodes.desc_sig_punctuation('=', '=')
2706
+ signode += addnodes.desc_sig_space()
2707
+ self.init.describe_signature(signode, mode, env, symbol)
2708
+
2709
+
2710
+ class ASTTypeWithInit(ASTBase):
2711
+ def __init__(self, type: ASTType, init: ASTInitializer) -> None:
2712
+ self.type = type
2713
+ self.init = init
2714
+
2715
+ @property
2716
+ def name(self) -> ASTNestedName:
2717
+ return self.type.name
2718
+
2719
+ @property
2720
+ def isPack(self) -> bool:
2721
+ return self.type.isPack
2722
+
2723
+ def get_id(self, version: int, objectType: str | None = None,
2724
+ symbol: Symbol | None = None) -> str:
2725
+ if objectType != 'member':
2726
+ return self.type.get_id(version, objectType)
2727
+ if version == 1:
2728
+ return (symbol.get_full_nested_name().get_id(version) + '__' +
2729
+ self.type.get_id(version))
2730
+ return symbol.get_full_nested_name().get_id(version)
2731
+
2732
+ def _stringify(self, transform: StringifyTransform) -> str:
2733
+ res = []
2734
+ res.append(transform(self.type))
2735
+ if self.init:
2736
+ res.append(transform(self.init))
2737
+ return ''.join(res)
2738
+
2739
+ def describe_signature(self, signode: TextElement, mode: str,
2740
+ env: BuildEnvironment, symbol: Symbol) -> None:
2741
+ verify_description_mode(mode)
2742
+ self.type.describe_signature(signode, mode, env, symbol)
2743
+ if self.init:
2744
+ self.init.describe_signature(signode, mode, env, symbol)
2745
+
2746
+
2747
+ class ASTTypeUsing(ASTBase):
2748
+ def __init__(self, name: ASTNestedName, type: ASTType | None) -> None:
2749
+ self.name = name
2750
+ self.type = type
2751
+
2752
+ def get_id(self, version: int, objectType: str | None = None,
2753
+ symbol: Symbol | None = None) -> str:
2754
+ if version == 1:
2755
+ raise NoOldIdError
2756
+ return symbol.get_full_nested_name().get_id(version)
2757
+
2758
+ def _stringify(self, transform: StringifyTransform) -> str:
2759
+ res = []
2760
+ res.append(transform(self.name))
2761
+ if self.type:
2762
+ res.append(' = ')
2763
+ res.append(transform(self.type))
2764
+ return ''.join(res)
2765
+
2766
+ def get_type_declaration_prefix(self) -> str:
2767
+ return 'using'
2768
+
2769
+ def describe_signature(self, signode: TextElement, mode: str,
2770
+ env: BuildEnvironment, symbol: Symbol) -> None:
2771
+ verify_description_mode(mode)
2772
+ self.name.describe_signature(signode, mode, env, symbol=symbol)
2773
+ if self.type:
2774
+ signode += addnodes.desc_sig_space()
2775
+ signode += addnodes.desc_sig_punctuation('=', '=')
2776
+ signode += addnodes.desc_sig_space()
2777
+ self.type.describe_signature(signode, 'markType', env, symbol=symbol)
2778
+
2779
+
2780
+ # Other declarations
2781
+ ##############################################################################################
2782
+
2783
+ class ASTConcept(ASTBase):
2784
+ def __init__(self, nestedName: ASTNestedName, initializer: ASTInitializer) -> None:
2785
+ self.nestedName = nestedName
2786
+ self.initializer = initializer
2787
+
2788
+ @property
2789
+ def name(self) -> ASTNestedName:
2790
+ return self.nestedName
2791
+
2792
+ def get_id(self, version: int, objectType: str | None = None,
2793
+ symbol: Symbol | None = None) -> str:
2794
+ if version == 1:
2795
+ raise NoOldIdError
2796
+ return symbol.get_full_nested_name().get_id(version)
2797
+
2798
+ def _stringify(self, transform: StringifyTransform) -> str:
2799
+ res = transform(self.nestedName)
2800
+ if self.initializer:
2801
+ res += transform(self.initializer)
2802
+ return res
2803
+
2804
+ def describe_signature(self, signode: TextElement, mode: str,
2805
+ env: BuildEnvironment, symbol: Symbol) -> None:
2806
+ self.nestedName.describe_signature(signode, mode, env, symbol)
2807
+ if self.initializer:
2808
+ self.initializer.describe_signature(signode, mode, env, symbol)
2809
+
2810
+
2811
+ class ASTBaseClass(ASTBase):
2812
+ def __init__(self, name: ASTNestedName, visibility: str,
2813
+ virtual: bool, pack: bool) -> None:
2814
+ self.name = name
2815
+ self.visibility = visibility
2816
+ self.virtual = virtual
2817
+ self.pack = pack
2818
+
2819
+ def _stringify(self, transform: StringifyTransform) -> str:
2820
+ res = []
2821
+ if self.visibility is not None:
2822
+ res.append(self.visibility)
2823
+ res.append(' ')
2824
+ if self.virtual:
2825
+ res.append('virtual ')
2826
+ res.append(transform(self.name))
2827
+ if self.pack:
2828
+ res.append('...')
2829
+ return ''.join(res)
2830
+
2831
+ def describe_signature(self, signode: TextElement, mode: str,
2832
+ env: BuildEnvironment, symbol: Symbol) -> None:
2833
+ verify_description_mode(mode)
2834
+ if self.visibility is not None:
2835
+ signode += addnodes.desc_sig_keyword(self.visibility,
2836
+ self.visibility)
2837
+ signode += addnodes.desc_sig_space()
2838
+ if self.virtual:
2839
+ signode += addnodes.desc_sig_keyword('virtual', 'virtual')
2840
+ signode += addnodes.desc_sig_space()
2841
+ self.name.describe_signature(signode, 'markType', env, symbol=symbol)
2842
+ if self.pack:
2843
+ signode += addnodes.desc_sig_punctuation('...', '...')
2844
+
2845
+
2846
+ class ASTClass(ASTBase):
2847
+ def __init__(self, name: ASTNestedName, final: bool, bases: list[ASTBaseClass],
2848
+ attrs: ASTAttributeList) -> None:
2849
+ self.name = name
2850
+ self.final = final
2851
+ self.bases = bases
2852
+ self.attrs = attrs
2853
+
2854
+ def get_id(self, version: int, objectType: str, symbol: Symbol) -> str:
2855
+ return symbol.get_full_nested_name().get_id(version)
2856
+
2857
+ def _stringify(self, transform: StringifyTransform) -> str:
2858
+ res = []
2859
+ res.append(transform(self.attrs))
2860
+ if len(self.attrs) != 0:
2861
+ res.append(' ')
2862
+ res.append(transform(self.name))
2863
+ if self.final:
2864
+ res.append(' final')
2865
+ if len(self.bases) > 0:
2866
+ res.append(' : ')
2867
+ first = True
2868
+ for b in self.bases:
2869
+ if not first:
2870
+ res.append(', ')
2871
+ first = False
2872
+ res.append(transform(b))
2873
+ return ''.join(res)
2874
+
2875
+ def describe_signature(self, signode: TextElement, mode: str,
2876
+ env: BuildEnvironment, symbol: Symbol) -> None:
2877
+ verify_description_mode(mode)
2878
+ self.attrs.describe_signature(signode)
2879
+ if len(self.attrs) != 0:
2880
+ signode += addnodes.desc_sig_space()
2881
+ self.name.describe_signature(signode, mode, env, symbol=symbol)
2882
+ if self.final:
2883
+ signode += addnodes.desc_sig_space()
2884
+ signode += addnodes.desc_sig_keyword('final', 'final')
2885
+ if len(self.bases) > 0:
2886
+ signode += addnodes.desc_sig_space()
2887
+ signode += addnodes.desc_sig_punctuation(':', ':')
2888
+ signode += addnodes.desc_sig_space()
2889
+ for b in self.bases:
2890
+ b.describe_signature(signode, mode, env, symbol=symbol)
2891
+ signode += addnodes.desc_sig_punctuation(',', ',')
2892
+ signode += addnodes.desc_sig_space()
2893
+ signode.pop()
2894
+ signode.pop()
2895
+
2896
+
2897
+ class ASTUnion(ASTBase):
2898
+ def __init__(self, name: ASTNestedName, attrs: ASTAttributeList) -> None:
2899
+ self.name = name
2900
+ self.attrs = attrs
2901
+
2902
+ def get_id(self, version: int, objectType: str, symbol: Symbol) -> str:
2903
+ if version == 1:
2904
+ raise NoOldIdError
2905
+ return symbol.get_full_nested_name().get_id(version)
2906
+
2907
+ def _stringify(self, transform: StringifyTransform) -> str:
2908
+ res = []
2909
+ res.append(transform(self.attrs))
2910
+ if len(self.attrs) != 0:
2911
+ res.append(' ')
2912
+ res.append(transform(self.name))
2913
+ return ''.join(res)
2914
+
2915
+ def describe_signature(self, signode: TextElement, mode: str,
2916
+ env: BuildEnvironment, symbol: Symbol) -> None:
2917
+ verify_description_mode(mode)
2918
+ self.attrs.describe_signature(signode)
2919
+ if len(self.attrs) != 0:
2920
+ signode += addnodes.desc_sig_space()
2921
+ self.name.describe_signature(signode, mode, env, symbol=symbol)
2922
+
2923
+
2924
+ class ASTEnum(ASTBase):
2925
+ def __init__(self, name: ASTNestedName, scoped: str, underlyingType: ASTType,
2926
+ attrs: ASTAttributeList) -> None:
2927
+ self.name = name
2928
+ self.scoped = scoped
2929
+ self.underlyingType = underlyingType
2930
+ self.attrs = attrs
2931
+
2932
+ def get_id(self, version: int, objectType: str, symbol: Symbol) -> str:
2933
+ if version == 1:
2934
+ raise NoOldIdError
2935
+ return symbol.get_full_nested_name().get_id(version)
2936
+
2937
+ def _stringify(self, transform: StringifyTransform) -> str:
2938
+ res = []
2939
+ if self.scoped:
2940
+ res.append(self.scoped)
2941
+ res.append(' ')
2942
+ res.append(transform(self.attrs))
2943
+ if len(self.attrs) != 0:
2944
+ res.append(' ')
2945
+ res.append(transform(self.name))
2946
+ if self.underlyingType:
2947
+ res.append(' : ')
2948
+ res.append(transform(self.underlyingType))
2949
+ return ''.join(res)
2950
+
2951
+ def describe_signature(self, signode: TextElement, mode: str,
2952
+ env: BuildEnvironment, symbol: Symbol) -> None:
2953
+ verify_description_mode(mode)
2954
+ # self.scoped has been done by the CPPEnumObject
2955
+ self.attrs.describe_signature(signode)
2956
+ if len(self.attrs) != 0:
2957
+ signode += addnodes.desc_sig_space()
2958
+ self.name.describe_signature(signode, mode, env, symbol=symbol)
2959
+ if self.underlyingType:
2960
+ signode += addnodes.desc_sig_space()
2961
+ signode += addnodes.desc_sig_punctuation(':', ':')
2962
+ signode += addnodes.desc_sig_space()
2963
+ self.underlyingType.describe_signature(signode, 'noneIsName',
2964
+ env, symbol=symbol)
2965
+
2966
+
2967
+ class ASTEnumerator(ASTBase):
2968
+ def __init__(self, name: ASTNestedName, init: ASTInitializer | None,
2969
+ attrs: ASTAttributeList) -> None:
2970
+ self.name = name
2971
+ self.init = init
2972
+ self.attrs = attrs
2973
+
2974
+ def get_id(self, version: int, objectType: str, symbol: Symbol) -> str:
2975
+ if version == 1:
2976
+ raise NoOldIdError
2977
+ return symbol.get_full_nested_name().get_id(version)
2978
+
2979
+ def _stringify(self, transform: StringifyTransform) -> str:
2980
+ res = []
2981
+ res.append(transform(self.name))
2982
+ if len(self.attrs) != 0:
2983
+ res.append(' ')
2984
+ res.append(transform(self.attrs))
2985
+ if self.init:
2986
+ res.append(transform(self.init))
2987
+ return ''.join(res)
2988
+
2989
+ def describe_signature(self, signode: TextElement, mode: str,
2990
+ env: BuildEnvironment, symbol: Symbol) -> None:
2991
+ verify_description_mode(mode)
2992
+ self.name.describe_signature(signode, mode, env, symbol)
2993
+ if len(self.attrs) != 0:
2994
+ signode += addnodes.desc_sig_space()
2995
+ self.attrs.describe_signature(signode)
2996
+ if self.init:
2997
+ self.init.describe_signature(signode, 'markType', env, symbol)
2998
+
2999
+
3000
+ ################################################################################
3001
+ # Templates
3002
+ ################################################################################
3003
+
3004
+ # Parameters
3005
+ ################################################################################
3006
+
3007
+ class ASTTemplateParam(ASTBase):
3008
+ def get_identifier(self) -> ASTIdentifier:
3009
+ raise NotImplementedError(repr(self))
3010
+
3011
+ def get_id(self, version: int) -> str:
3012
+ raise NotImplementedError(repr(self))
3013
+
3014
+ def describe_signature(self, parentNode: TextElement, mode: str,
3015
+ env: BuildEnvironment, symbol: Symbol) -> None:
3016
+ raise NotImplementedError(repr(self))
3017
+
3018
+ @property
3019
+ def isPack(self) -> bool:
3020
+ raise NotImplementedError(repr(self))
3021
+
3022
+ @property
3023
+ def name(self) -> ASTNestedName:
3024
+ raise NotImplementedError(repr(self))
3025
+
3026
+
3027
+ class ASTTemplateKeyParamPackIdDefault(ASTTemplateParam):
3028
+ def __init__(self, key: str, identifier: ASTIdentifier,
3029
+ parameterPack: bool, default: ASTType) -> None:
3030
+ assert key
3031
+ if parameterPack:
3032
+ assert default is None
3033
+ self.key = key
3034
+ self.identifier = identifier
3035
+ self.parameterPack = parameterPack
3036
+ self.default = default
3037
+
3038
+ def get_identifier(self) -> ASTIdentifier:
3039
+ return self.identifier
3040
+
3041
+ def get_id(self, version: int) -> str:
3042
+ assert version >= 2
3043
+ # this is not part of the normal name mangling in C++
3044
+ res = []
3045
+ if self.parameterPack:
3046
+ res.append('Dp')
3047
+ else:
3048
+ res.append('0') # we need to put something
3049
+ return ''.join(res)
3050
+
3051
+ def _stringify(self, transform: StringifyTransform) -> str:
3052
+ res = [self.key]
3053
+ if self.parameterPack:
3054
+ if self.identifier:
3055
+ res.append(' ')
3056
+ res.append('...')
3057
+ if self.identifier:
3058
+ if not self.parameterPack:
3059
+ res.append(' ')
3060
+ res.append(transform(self.identifier))
3061
+ if self.default:
3062
+ res.append(' = ')
3063
+ res.append(transform(self.default))
3064
+ return ''.join(res)
3065
+
3066
+ def describe_signature(self, signode: TextElement, mode: str,
3067
+ env: BuildEnvironment, symbol: Symbol) -> None:
3068
+ signode += addnodes.desc_sig_keyword(self.key, self.key)
3069
+ if self.parameterPack:
3070
+ if self.identifier:
3071
+ signode += addnodes.desc_sig_space()
3072
+ signode += addnodes.desc_sig_punctuation('...', '...')
3073
+ if self.identifier:
3074
+ if not self.parameterPack:
3075
+ signode += addnodes.desc_sig_space()
3076
+ self.identifier.describe_signature(signode, mode, env, '', '', symbol)
3077
+ if self.default:
3078
+ signode += addnodes.desc_sig_space()
3079
+ signode += addnodes.desc_sig_punctuation('=', '=')
3080
+ signode += addnodes.desc_sig_space()
3081
+ self.default.describe_signature(signode, 'markType', env, symbol)
3082
+
3083
+
3084
+ class ASTTemplateParamType(ASTTemplateParam):
3085
+ def __init__(self, data: ASTTemplateKeyParamPackIdDefault) -> None:
3086
+ assert data
3087
+ self.data = data
3088
+
3089
+ @property
3090
+ def name(self) -> ASTNestedName:
3091
+ id = self.get_identifier()
3092
+ return ASTNestedName([ASTNestedNameElement(id, None)], [False], rooted=False)
3093
+
3094
+ @property
3095
+ def isPack(self) -> bool:
3096
+ return self.data.parameterPack
3097
+
3098
+ def get_identifier(self) -> ASTIdentifier:
3099
+ return self.data.get_identifier()
3100
+
3101
+ def get_id(
3102
+ self, version: int, objectType: str | None = None, symbol: Symbol | None = None,
3103
+ ) -> str:
3104
+ # this is not part of the normal name mangling in C++
3105
+ assert version >= 2
3106
+ if symbol:
3107
+ # the anchor will be our parent
3108
+ return symbol.parent.declaration.get_id(version, prefixed=False)
3109
+ else:
3110
+ return self.data.get_id(version)
3111
+
3112
+ def _stringify(self, transform: StringifyTransform) -> str:
3113
+ return transform(self.data)
3114
+
3115
+ def describe_signature(self, signode: TextElement, mode: str,
3116
+ env: BuildEnvironment, symbol: Symbol) -> None:
3117
+ self.data.describe_signature(signode, mode, env, symbol)
3118
+
3119
+
3120
+ class ASTTemplateParamTemplateType(ASTTemplateParam):
3121
+ def __init__(self, nestedParams: ASTTemplateParams,
3122
+ data: ASTTemplateKeyParamPackIdDefault) -> None:
3123
+ assert nestedParams
3124
+ assert data
3125
+ self.nestedParams = nestedParams
3126
+ self.data = data
3127
+
3128
+ @property
3129
+ def name(self) -> ASTNestedName:
3130
+ id = self.get_identifier()
3131
+ return ASTNestedName([ASTNestedNameElement(id, None)], [False], rooted=False)
3132
+
3133
+ @property
3134
+ def isPack(self) -> bool:
3135
+ return self.data.parameterPack
3136
+
3137
+ def get_identifier(self) -> ASTIdentifier:
3138
+ return self.data.get_identifier()
3139
+
3140
+ def get_id(
3141
+ self, version: int, objectType: str | None = None, symbol: Symbol | None = None,
3142
+ ) -> str:
3143
+ assert version >= 2
3144
+ # this is not part of the normal name mangling in C++
3145
+ if symbol:
3146
+ # the anchor will be our parent
3147
+ return symbol.parent.declaration.get_id(version, prefixed=None)
3148
+ else:
3149
+ return self.nestedParams.get_id(version) + self.data.get_id(version)
3150
+
3151
+ def _stringify(self, transform: StringifyTransform) -> str:
3152
+ return transform(self.nestedParams) + transform(self.data)
3153
+
3154
+ def describe_signature(self, signode: TextElement, mode: str,
3155
+ env: BuildEnvironment, symbol: Symbol) -> None:
3156
+ self.nestedParams.describe_signature(signode, 'noneIsName', env, symbol)
3157
+ signode += addnodes.desc_sig_space()
3158
+ self.data.describe_signature(signode, mode, env, symbol)
3159
+
3160
+
3161
+ class ASTTemplateParamNonType(ASTTemplateParam):
3162
+ def __init__(self,
3163
+ param: ASTTypeWithInit | ASTTemplateParamConstrainedTypeWithInit,
3164
+ parameterPack: bool = False) -> None:
3165
+ assert param
3166
+ self.param = param
3167
+ self.parameterPack = parameterPack
3168
+
3169
+ @property
3170
+ def name(self) -> ASTNestedName:
3171
+ id = self.get_identifier()
3172
+ return ASTNestedName([ASTNestedNameElement(id, None)], [False], rooted=False)
3173
+
3174
+ @property
3175
+ def isPack(self) -> bool:
3176
+ return self.param.isPack or self.parameterPack
3177
+
3178
+ def get_identifier(self) -> ASTIdentifier:
3179
+ name = self.param.name
3180
+ if name:
3181
+ assert len(name.names) == 1
3182
+ assert name.names[0].identOrOp
3183
+ assert not name.names[0].templateArgs
3184
+ res = name.names[0].identOrOp
3185
+ assert isinstance(res, ASTIdentifier)
3186
+ return res
3187
+ else:
3188
+ return None
3189
+
3190
+ def get_id(
3191
+ self, version: int, objectType: str | None = None, symbol: Symbol | None = None,
3192
+ ) -> str:
3193
+ assert version >= 2
3194
+ # this is not part of the normal name mangling in C++
3195
+ if symbol:
3196
+ # the anchor will be our parent
3197
+ return symbol.parent.declaration.get_id(version, prefixed=None)
3198
+ else:
3199
+ res = '_'
3200
+ if self.parameterPack:
3201
+ res += 'Dp'
3202
+ return res + self.param.get_id(version)
3203
+
3204
+ def _stringify(self, transform: StringifyTransform) -> str:
3205
+ res = transform(self.param)
3206
+ if self.parameterPack:
3207
+ res += '...'
3208
+ return res
3209
+
3210
+ def describe_signature(self, signode: TextElement, mode: str,
3211
+ env: BuildEnvironment, symbol: Symbol) -> None:
3212
+ self.param.describe_signature(signode, mode, env, symbol)
3213
+ if self.parameterPack:
3214
+ signode += addnodes.desc_sig_punctuation('...', '...')
3215
+
3216
+
3217
+ class ASTTemplateParams(ASTBase):
3218
+ def __init__(self, params: list[ASTTemplateParam],
3219
+ requiresClause: ASTRequiresClause | None) -> None:
3220
+ assert params is not None
3221
+ self.params = params
3222
+ self.requiresClause = requiresClause
3223
+
3224
+ def get_id(self, version: int, excludeRequires: bool = False) -> str:
3225
+ assert version >= 2
3226
+ res = []
3227
+ res.append("I")
3228
+ res.extend(param.get_id(version) for param in self.params)
3229
+ res.append("E")
3230
+ if not excludeRequires and self.requiresClause:
3231
+ res.extend(['IQ', self.requiresClause.expr.get_id(version), 'E'])
3232
+ return ''.join(res)
3233
+
3234
+ def _stringify(self, transform: StringifyTransform) -> str:
3235
+ res = []
3236
+ res.append("template<")
3237
+ res.append(", ".join(transform(a) for a in self.params))
3238
+ res.append("> ")
3239
+ if self.requiresClause is not None:
3240
+ res.append(transform(self.requiresClause))
3241
+ res.append(" ")
3242
+ return ''.join(res)
3243
+
3244
+ def describe_signature(self, signode: TextElement, mode: str,
3245
+ env: BuildEnvironment, symbol: Symbol) -> None:
3246
+ signode += addnodes.desc_sig_keyword('template', 'template')
3247
+ signode += addnodes.desc_sig_punctuation('<', '<')
3248
+ first = True
3249
+ for param in self.params:
3250
+ if not first:
3251
+ signode += addnodes.desc_sig_punctuation(',', ',')
3252
+ signode += addnodes.desc_sig_space()
3253
+ first = False
3254
+ param.describe_signature(signode, mode, env, symbol)
3255
+ signode += addnodes.desc_sig_punctuation('>', '>')
3256
+ if self.requiresClause is not None:
3257
+ signode += addnodes.desc_sig_space()
3258
+ self.requiresClause.describe_signature(signode, mode, env, symbol)
3259
+
3260
+ def describe_signature_as_introducer(
3261
+ self, parentNode: desc_signature, mode: str, env: BuildEnvironment,
3262
+ symbol: Symbol, lineSpec: bool) -> None:
3263
+ def makeLine(parentNode: desc_signature) -> addnodes.desc_signature_line:
3264
+ signode = addnodes.desc_signature_line()
3265
+ parentNode += signode
3266
+ signode.sphinx_line_type = 'templateParams'
3267
+ return signode
3268
+ lineNode = makeLine(parentNode)
3269
+ lineNode += addnodes.desc_sig_keyword('template', 'template')
3270
+ lineNode += addnodes.desc_sig_punctuation('<', '<')
3271
+ first = True
3272
+ for param in self.params:
3273
+ if not first:
3274
+ lineNode += addnodes.desc_sig_punctuation(',', ',')
3275
+ lineNode += addnodes.desc_sig_space()
3276
+ first = False
3277
+ if lineSpec:
3278
+ lineNode = makeLine(parentNode)
3279
+ param.describe_signature(lineNode, mode, env, symbol)
3280
+ if lineSpec and not first:
3281
+ lineNode = makeLine(parentNode)
3282
+ lineNode += addnodes.desc_sig_punctuation('>', '>')
3283
+ if self.requiresClause:
3284
+ reqNode = addnodes.desc_signature_line()
3285
+ reqNode.sphinx_line_type = 'requiresClause'
3286
+ parentNode += reqNode
3287
+ self.requiresClause.describe_signature(reqNode, 'markType', env, symbol)
3288
+
3289
+
3290
+ # Template introducers
3291
+ ################################################################################
3292
+
3293
+ class ASTTemplateIntroductionParameter(ASTBase):
3294
+ def __init__(self, identifier: ASTIdentifier, parameterPack: bool) -> None:
3295
+ self.identifier = identifier
3296
+ self.parameterPack = parameterPack
3297
+
3298
+ @property
3299
+ def name(self) -> ASTNestedName:
3300
+ id = self.get_identifier()
3301
+ return ASTNestedName([ASTNestedNameElement(id, None)], [False], rooted=False)
3302
+
3303
+ @property
3304
+ def isPack(self) -> bool:
3305
+ return self.parameterPack
3306
+
3307
+ def get_identifier(self) -> ASTIdentifier:
3308
+ return self.identifier
3309
+
3310
+ def get_id(
3311
+ self, version: int, objectType: str | None = None, symbol: Symbol | None = None,
3312
+ ) -> str:
3313
+ assert version >= 2
3314
+ # this is not part of the normal name mangling in C++
3315
+ if symbol:
3316
+ # the anchor will be our parent
3317
+ return symbol.parent.declaration.get_id(version, prefixed=None)
3318
+ else:
3319
+ if self.parameterPack:
3320
+ return 'Dp'
3321
+ else:
3322
+ return '0' # we need to put something
3323
+
3324
+ def get_id_as_arg(self, version: int) -> str:
3325
+ assert version >= 2
3326
+ # used for the implicit requires clause
3327
+ res = self.identifier.get_id(version)
3328
+ if self.parameterPack:
3329
+ return 'sp' + res
3330
+ else:
3331
+ return res
3332
+
3333
+ def _stringify(self, transform: StringifyTransform) -> str:
3334
+ res = []
3335
+ if self.parameterPack:
3336
+ res.append('...')
3337
+ res.append(transform(self.identifier))
3338
+ return ''.join(res)
3339
+
3340
+ def describe_signature(self, signode: TextElement, mode: str,
3341
+ env: BuildEnvironment, symbol: Symbol) -> None:
3342
+ if self.parameterPack:
3343
+ signode += addnodes.desc_sig_punctuation('...', '...')
3344
+ self.identifier.describe_signature(signode, mode, env, '', '', symbol)
3345
+
3346
+
3347
+ class ASTTemplateIntroduction(ASTBase):
3348
+ def __init__(self, concept: ASTNestedName,
3349
+ params: list[ASTTemplateIntroductionParameter]) -> None:
3350
+ assert len(params) > 0
3351
+ self.concept = concept
3352
+ self.params = params
3353
+
3354
+ def get_id(self, version: int) -> str:
3355
+ assert version >= 2
3356
+ return ''.join([
3357
+ # first do the same as a normal template parameter list
3358
+ "I",
3359
+ *(param.get_id(version) for param in self.params),
3360
+ "E",
3361
+ # let's use X expr E, which is otherwise for constant template args
3362
+ "X",
3363
+ self.concept.get_id(version),
3364
+ "I",
3365
+ *(param.get_id_as_arg(version) for param in self.params),
3366
+ "E",
3367
+ "E",
3368
+ ])
3369
+
3370
+ def _stringify(self, transform: StringifyTransform) -> str:
3371
+ res = []
3372
+ res.append(transform(self.concept))
3373
+ res.append('{')
3374
+ res.append(', '.join(transform(param) for param in self.params))
3375
+ res.append('} ')
3376
+ return ''.join(res)
3377
+
3378
+ def describe_signature_as_introducer(
3379
+ self, parentNode: desc_signature, mode: str,
3380
+ env: BuildEnvironment, symbol: Symbol, lineSpec: bool) -> None:
3381
+ # Note: 'lineSpec' has no effect on template introductions.
3382
+ signode = addnodes.desc_signature_line()
3383
+ parentNode += signode
3384
+ signode.sphinx_line_type = 'templateIntroduction'
3385
+ self.concept.describe_signature(signode, 'markType', env, symbol)
3386
+ signode += addnodes.desc_sig_punctuation('{', '{')
3387
+ first = True
3388
+ for param in self.params:
3389
+ if not first:
3390
+ signode += addnodes.desc_sig_punctuation(',', ',')
3391
+ signode += addnodes.desc_sig_space()
3392
+ first = False
3393
+ param.describe_signature(signode, mode, env, symbol)
3394
+ signode += addnodes.desc_sig_punctuation('}', '}')
3395
+
3396
+
3397
+ ################################################################################
3398
+
3399
+ class ASTTemplateDeclarationPrefix(ASTBase):
3400
+ def __init__(self,
3401
+ templates: list[ASTTemplateParams | ASTTemplateIntroduction] | None) -> None:
3402
+ # templates is None means it's an explicit instantiation of a variable
3403
+ self.templates = templates
3404
+
3405
+ def get_requires_clause_in_last(self) -> ASTRequiresClause | None:
3406
+ if self.templates is None:
3407
+ return None
3408
+ lastList = self.templates[-1]
3409
+ if not isinstance(lastList, ASTTemplateParams):
3410
+ return None
3411
+ return lastList.requiresClause # which may be None
3412
+
3413
+ def get_id_except_requires_clause_in_last(self, version: int) -> str:
3414
+ assert version >= 2
3415
+ # This is not part of the Itanium ABI mangling system.
3416
+ res = []
3417
+ lastIndex = len(self.templates) - 1
3418
+ for i, t in enumerate(self.templates):
3419
+ if isinstance(t, ASTTemplateParams):
3420
+ res.append(t.get_id(version, excludeRequires=(i == lastIndex)))
3421
+ else:
3422
+ res.append(t.get_id(version))
3423
+ return ''.join(res)
3424
+
3425
+ def _stringify(self, transform: StringifyTransform) -> str:
3426
+ return ''.join(map(transform, self.templates))
3427
+
3428
+ def describe_signature(self, signode: desc_signature, mode: str,
3429
+ env: BuildEnvironment, symbol: Symbol, lineSpec: bool) -> None:
3430
+ verify_description_mode(mode)
3431
+ for t in self.templates:
3432
+ t.describe_signature_as_introducer(signode, 'lastIsName', env, symbol, lineSpec)
3433
+
3434
+
3435
+ class ASTRequiresClause(ASTBase):
3436
+ def __init__(self, expr: ASTExpression) -> None:
3437
+ self.expr = expr
3438
+
3439
+ def _stringify(self, transform: StringifyTransform) -> str:
3440
+ return 'requires ' + transform(self.expr)
3441
+
3442
+ def describe_signature(self, signode: nodes.TextElement, mode: str,
3443
+ env: BuildEnvironment, symbol: Symbol) -> None:
3444
+ signode += addnodes.desc_sig_keyword('requires', 'requires')
3445
+ signode += addnodes.desc_sig_space()
3446
+ self.expr.describe_signature(signode, mode, env, symbol)
3447
+
3448
+
3449
+ ################################################################################
3450
+ ################################################################################
3451
+
3452
+ class ASTDeclaration(ASTBase):
3453
+ def __init__(self, objectType: str, directiveType: str | None = None,
3454
+ visibility: str | None = None,
3455
+ templatePrefix: ASTTemplateDeclarationPrefix | None = None,
3456
+ declaration: Any = None,
3457
+ trailingRequiresClause: ASTRequiresClause | None = None,
3458
+ semicolon: bool = False) -> None:
3459
+ self.objectType = objectType
3460
+ self.directiveType = directiveType
3461
+ self.visibility = visibility
3462
+ self.templatePrefix = templatePrefix
3463
+ self.declaration = declaration
3464
+ self.trailingRequiresClause = trailingRequiresClause
3465
+ self.semicolon = semicolon
3466
+
3467
+ self.symbol: Symbol | None = None
3468
+ # set by CPPObject._add_enumerator_to_parent
3469
+ self.enumeratorScopedSymbol: Symbol | None = None
3470
+
3471
+ # the cache assumes that by the time get_newest_id is called, no
3472
+ # further changes will be made to this object
3473
+ self._newest_id_cache: str | None = None
3474
+
3475
+ def clone(self) -> ASTDeclaration:
3476
+ templatePrefixClone = self.templatePrefix.clone() if self.templatePrefix else None
3477
+ trailingRequiresClasueClone = self.trailingRequiresClause.clone() \
3478
+ if self.trailingRequiresClause else None
3479
+ return ASTDeclaration(self.objectType, self.directiveType, self.visibility,
3480
+ templatePrefixClone,
3481
+ self.declaration.clone(), trailingRequiresClasueClone,
3482
+ self.semicolon)
3483
+
3484
+ @property
3485
+ def name(self) -> ASTNestedName:
3486
+ return self.declaration.name
3487
+
3488
+ @property
3489
+ def function_params(self) -> list[ASTFunctionParameter]:
3490
+ if self.objectType != 'function':
3491
+ return None
3492
+ return self.declaration.function_params
3493
+
3494
+ def get_id(self, version: int, prefixed: bool = True) -> str:
3495
+ if version == 1:
3496
+ if self.templatePrefix or self.trailingRequiresClause:
3497
+ raise NoOldIdError
3498
+ if self.objectType == 'enumerator' and self.enumeratorScopedSymbol:
3499
+ return self.enumeratorScopedSymbol.declaration.get_id(version)
3500
+ return self.declaration.get_id(version, self.objectType, self.symbol)
3501
+ # version >= 2
3502
+ if self.objectType == 'enumerator' and self.enumeratorScopedSymbol:
3503
+ return self.enumeratorScopedSymbol.declaration.get_id(version, prefixed)
3504
+ if prefixed:
3505
+ res = [_id_prefix[version]]
3506
+ else:
3507
+ res = []
3508
+ # (See also https://github.com/sphinx-doc/sphinx/pull/10286#issuecomment-1168102147)
3509
+ # The first implementation of requires clauses only supported a single clause after the
3510
+ # template prefix, and no trailing clause. It put the ID after the template parameter
3511
+ # list, i.e.,
3512
+ # "I" + template_parameter_list_id + "E" + "IQ" + requires_clause_id + "E"
3513
+ # but the second implementation associates the requires clause with each list, i.e.,
3514
+ # "I" + template_parameter_list_id + "IQ" + requires_clause_id + "E" + "E"
3515
+ # To avoid making a new ID version, we make an exception for the last requires clause
3516
+ # in the template prefix, and still put it in the end.
3517
+ # As we now support trailing requires clauses we add that as if it was a conjunction.
3518
+ if self.templatePrefix is not None:
3519
+ res.append(self.templatePrefix.get_id_except_requires_clause_in_last(version))
3520
+ requiresClauseInLast = self.templatePrefix.get_requires_clause_in_last()
3521
+ else:
3522
+ requiresClauseInLast = None
3523
+
3524
+ if requiresClauseInLast or self.trailingRequiresClause:
3525
+ if version < 4:
3526
+ raise NoOldIdError
3527
+ res.append('IQ')
3528
+ if requiresClauseInLast and self.trailingRequiresClause:
3529
+ # make a conjunction of them
3530
+ res.append('aa')
3531
+ if requiresClauseInLast:
3532
+ res.append(requiresClauseInLast.expr.get_id(version))
3533
+ if self.trailingRequiresClause:
3534
+ res.append(self.trailingRequiresClause.expr.get_id(version))
3535
+ res.append('E')
3536
+ res.append(self.declaration.get_id(version, self.objectType, self.symbol))
3537
+ return ''.join(res)
3538
+
3539
+ def get_newest_id(self) -> str:
3540
+ if self._newest_id_cache is None:
3541
+ self._newest_id_cache = self.get_id(_max_id, True)
3542
+ return self._newest_id_cache
3543
+
3544
+ def _stringify(self, transform: StringifyTransform) -> str:
3545
+ res = []
3546
+ if self.visibility and self.visibility != "public":
3547
+ res.append(self.visibility)
3548
+ res.append(' ')
3549
+ if self.templatePrefix:
3550
+ res.append(transform(self.templatePrefix))
3551
+ res.append(transform(self.declaration))
3552
+ if self.trailingRequiresClause:
3553
+ res.append(' ')
3554
+ res.append(transform(self.trailingRequiresClause))
3555
+ if self.semicolon:
3556
+ res.append(';')
3557
+ return ''.join(res)
3558
+
3559
+ def describe_signature(self, signode: desc_signature, mode: str,
3560
+ env: BuildEnvironment, options: dict[str, bool]) -> None:
3561
+ verify_description_mode(mode)
3562
+ assert self.symbol
3563
+ # The caller of the domain added a desc_signature node.
3564
+ # Always enable multiline:
3565
+ signode['is_multiline'] = True
3566
+ # Put each line in a desc_signature_line node.
3567
+ mainDeclNode = addnodes.desc_signature_line()
3568
+ mainDeclNode.sphinx_line_type = 'declarator'
3569
+ mainDeclNode['add_permalink'] = not self.symbol.isRedeclaration
3570
+
3571
+ if self.templatePrefix:
3572
+ self.templatePrefix.describe_signature(signode, mode, env,
3573
+ symbol=self.symbol,
3574
+ lineSpec=options.get('tparam-line-spec'))
3575
+ signode += mainDeclNode
3576
+ if self.visibility and self.visibility != "public":
3577
+ mainDeclNode += addnodes.desc_sig_keyword(self.visibility, self.visibility)
3578
+ mainDeclNode += addnodes.desc_sig_space()
3579
+ if self.objectType == 'type':
3580
+ prefix = self.declaration.get_type_declaration_prefix()
3581
+ mainDeclNode += addnodes.desc_sig_keyword(prefix, prefix)
3582
+ mainDeclNode += addnodes.desc_sig_space()
3583
+ elif self.objectType == 'concept':
3584
+ mainDeclNode += addnodes.desc_sig_keyword('concept', 'concept')
3585
+ mainDeclNode += addnodes.desc_sig_space()
3586
+ elif self.objectType in {'member', 'function'}:
3587
+ pass
3588
+ elif self.objectType == 'class':
3589
+ assert self.directiveType in ('class', 'struct')
3590
+ mainDeclNode += addnodes.desc_sig_keyword(self.directiveType, self.directiveType)
3591
+ mainDeclNode += addnodes.desc_sig_space()
3592
+ elif self.objectType == 'union':
3593
+ mainDeclNode += addnodes.desc_sig_keyword('union', 'union')
3594
+ mainDeclNode += addnodes.desc_sig_space()
3595
+ elif self.objectType == 'enum':
3596
+ mainDeclNode += addnodes.desc_sig_keyword('enum', 'enum')
3597
+ mainDeclNode += addnodes.desc_sig_space()
3598
+ if self.directiveType == 'enum-class':
3599
+ mainDeclNode += addnodes.desc_sig_keyword('class', 'class')
3600
+ mainDeclNode += addnodes.desc_sig_space()
3601
+ elif self.directiveType == 'enum-struct':
3602
+ mainDeclNode += addnodes.desc_sig_keyword('struct', 'struct')
3603
+ mainDeclNode += addnodes.desc_sig_space()
3604
+ else:
3605
+ assert self.directiveType == 'enum', self.directiveType
3606
+ elif self.objectType == 'enumerator':
3607
+ mainDeclNode += addnodes.desc_sig_keyword('enumerator', 'enumerator')
3608
+ mainDeclNode += addnodes.desc_sig_space()
3609
+ else:
3610
+ raise AssertionError(self.objectType)
3611
+ self.declaration.describe_signature(mainDeclNode, mode, env, self.symbol)
3612
+ lastDeclNode = mainDeclNode
3613
+ if self.trailingRequiresClause:
3614
+ trailingReqNode = addnodes.desc_signature_line()
3615
+ trailingReqNode.sphinx_line_type = 'trailingRequiresClause'
3616
+ signode.append(trailingReqNode)
3617
+ lastDeclNode = trailingReqNode
3618
+ self.trailingRequiresClause.describe_signature(
3619
+ trailingReqNode, 'markType', env, self.symbol)
3620
+ if self.semicolon:
3621
+ lastDeclNode += addnodes.desc_sig_punctuation(';', ';')
3622
+
3623
+
3624
+ class ASTNamespace(ASTBase):
3625
+ def __init__(self, nestedName: ASTNestedName,
3626
+ templatePrefix: ASTTemplateDeclarationPrefix) -> None:
3627
+ self.nestedName = nestedName
3628
+ self.templatePrefix = templatePrefix
3629
+
3630
+ def _stringify(self, transform: StringifyTransform) -> str:
3631
+ res = []
3632
+ if self.templatePrefix:
3633
+ res.append(transform(self.templatePrefix))
3634
+ res.append(transform(self.nestedName))
3635
+ return ''.join(res)