doc_data.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. /**************************************************************************/
  2. /* doc_data.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "core/io/xml_parser.h"
  32. #include "core/variant/variant.h"
  33. class DocData {
  34. public:
  35. struct ArgumentDoc {
  36. String name;
  37. String type;
  38. String enumeration;
  39. bool is_bitfield = false;
  40. String default_value;
  41. bool operator<(const ArgumentDoc &p_arg) const {
  42. if (name == p_arg.name) {
  43. return type < p_arg.type;
  44. }
  45. return name < p_arg.name;
  46. }
  47. static ArgumentDoc from_dict(const Dictionary &p_dict) {
  48. ArgumentDoc doc;
  49. if (p_dict.has("name")) {
  50. doc.name = p_dict["name"];
  51. }
  52. if (p_dict.has("type")) {
  53. doc.type = p_dict["type"];
  54. }
  55. if (p_dict.has("enumeration")) {
  56. doc.enumeration = p_dict["enumeration"];
  57. if (p_dict.has("is_bitfield")) {
  58. doc.is_bitfield = p_dict["is_bitfield"];
  59. }
  60. }
  61. if (p_dict.has("default_value")) {
  62. doc.default_value = p_dict["default_value"];
  63. }
  64. return doc;
  65. }
  66. static Dictionary to_dict(const ArgumentDoc &p_doc) {
  67. Dictionary dict;
  68. if (!p_doc.name.is_empty()) {
  69. dict["name"] = p_doc.name;
  70. }
  71. if (!p_doc.type.is_empty()) {
  72. dict["type"] = p_doc.type;
  73. }
  74. if (!p_doc.enumeration.is_empty()) {
  75. dict["enumeration"] = p_doc.enumeration;
  76. dict["is_bitfield"] = p_doc.is_bitfield;
  77. }
  78. if (!p_doc.default_value.is_empty()) {
  79. dict["default_value"] = p_doc.default_value;
  80. }
  81. return dict;
  82. }
  83. };
  84. struct MethodDoc {
  85. String name;
  86. String return_type;
  87. String return_enum;
  88. bool return_is_bitfield = false;
  89. String qualifiers;
  90. String description;
  91. bool is_deprecated = false;
  92. String deprecated_message;
  93. bool is_experimental = false;
  94. String experimental_message;
  95. Vector<ArgumentDoc> arguments;
  96. // NOTE: Only for GDScript for now. The rest argument is not saved to the XML file.
  97. ArgumentDoc rest_argument;
  98. Vector<int> errors_returned;
  99. String keywords;
  100. bool operator<(const MethodDoc &p_method) const {
  101. if (name == p_method.name) {
  102. // Must be an operator or a constructor since there is no other overloading
  103. if (name.left(8) == "operator") {
  104. if (arguments.size() == p_method.arguments.size()) {
  105. if (arguments.is_empty()) {
  106. return false;
  107. }
  108. return arguments[0].type < p_method.arguments[0].type;
  109. }
  110. return arguments.size() < p_method.arguments.size();
  111. } else {
  112. // Must be a constructor
  113. // We want this arbitrary order for a class "Foo":
  114. // - 1. Default constructor: Foo()
  115. // - 2. Copy constructor: Foo(Foo)
  116. // - 3+. Other constructors Foo(Bar, ...) based on first argument's name
  117. if (arguments.is_empty() || p_method.arguments.is_empty()) { // 1.
  118. return arguments.size() < p_method.arguments.size();
  119. }
  120. if (arguments[0].type == return_type || p_method.arguments[0].type == p_method.return_type) { // 2.
  121. return (arguments[0].type == return_type) || (p_method.arguments[0].type != p_method.return_type);
  122. }
  123. return arguments[0] < p_method.arguments[0];
  124. }
  125. }
  126. return name.naturalcasecmp_to(p_method.name) < 0;
  127. }
  128. static MethodDoc from_dict(const Dictionary &p_dict) {
  129. MethodDoc doc;
  130. if (p_dict.has("name")) {
  131. doc.name = p_dict["name"];
  132. }
  133. if (p_dict.has("return_type")) {
  134. doc.return_type = p_dict["return_type"];
  135. }
  136. if (p_dict.has("return_enum")) {
  137. doc.return_enum = p_dict["return_enum"];
  138. if (p_dict.has("return_is_bitfield")) {
  139. doc.return_is_bitfield = p_dict["return_is_bitfield"];
  140. }
  141. }
  142. if (p_dict.has("qualifiers")) {
  143. doc.qualifiers = p_dict["qualifiers"];
  144. }
  145. if (p_dict.has("description")) {
  146. doc.description = p_dict["description"];
  147. }
  148. #ifndef DISABLE_DEPRECATED
  149. if (p_dict.has("is_deprecated")) {
  150. doc.is_deprecated = p_dict["is_deprecated"];
  151. }
  152. if (p_dict.has("is_experimental")) {
  153. doc.is_experimental = p_dict["is_experimental"];
  154. }
  155. #endif
  156. if (p_dict.has("deprecated")) {
  157. doc.is_deprecated = true;
  158. doc.deprecated_message = p_dict["deprecated"];
  159. }
  160. if (p_dict.has("experimental")) {
  161. doc.is_experimental = true;
  162. doc.experimental_message = p_dict["experimental"];
  163. }
  164. Array arguments;
  165. if (p_dict.has("arguments")) {
  166. arguments = p_dict["arguments"];
  167. }
  168. for (int i = 0; i < arguments.size(); i++) {
  169. doc.arguments.push_back(ArgumentDoc::from_dict(arguments[i]));
  170. }
  171. Array errors_returned;
  172. if (p_dict.has("errors_returned")) {
  173. errors_returned = p_dict["errors_returned"];
  174. }
  175. for (int i = 0; i < errors_returned.size(); i++) {
  176. doc.errors_returned.push_back(errors_returned[i]);
  177. }
  178. if (p_dict.has("keywords")) {
  179. doc.keywords = p_dict["keywords"];
  180. }
  181. return doc;
  182. }
  183. static Dictionary to_dict(const MethodDoc &p_doc) {
  184. Dictionary dict;
  185. if (!p_doc.name.is_empty()) {
  186. dict["name"] = p_doc.name;
  187. }
  188. if (!p_doc.return_type.is_empty()) {
  189. dict["return_type"] = p_doc.return_type;
  190. }
  191. if (!p_doc.return_enum.is_empty()) {
  192. dict["return_enum"] = p_doc.return_enum;
  193. dict["return_is_bitfield"] = p_doc.return_is_bitfield;
  194. }
  195. if (!p_doc.qualifiers.is_empty()) {
  196. dict["qualifiers"] = p_doc.qualifiers;
  197. }
  198. if (!p_doc.description.is_empty()) {
  199. dict["description"] = p_doc.description;
  200. }
  201. if (p_doc.is_deprecated) {
  202. dict["deprecated"] = p_doc.deprecated_message;
  203. }
  204. if (p_doc.is_experimental) {
  205. dict["experimental"] = p_doc.experimental_message;
  206. }
  207. if (!p_doc.keywords.is_empty()) {
  208. dict["keywords"] = p_doc.keywords;
  209. }
  210. if (!p_doc.arguments.is_empty()) {
  211. Array arguments;
  212. for (int i = 0; i < p_doc.arguments.size(); i++) {
  213. arguments.push_back(ArgumentDoc::to_dict(p_doc.arguments[i]));
  214. }
  215. dict["arguments"] = arguments;
  216. }
  217. if (!p_doc.errors_returned.is_empty()) {
  218. Array errors_returned;
  219. for (int i = 0; i < p_doc.errors_returned.size(); i++) {
  220. errors_returned.push_back(p_doc.errors_returned[i]);
  221. }
  222. dict["errors_returned"] = errors_returned;
  223. }
  224. return dict;
  225. }
  226. };
  227. struct ConstantDoc {
  228. String name;
  229. String value;
  230. bool is_value_valid = false;
  231. String type;
  232. String enumeration;
  233. bool is_bitfield = false;
  234. String description;
  235. bool is_deprecated = false;
  236. String deprecated_message;
  237. bool is_experimental = false;
  238. String experimental_message;
  239. String keywords;
  240. bool operator<(const ConstantDoc &p_const) const {
  241. return name < p_const.name;
  242. }
  243. static ConstantDoc from_dict(const Dictionary &p_dict) {
  244. ConstantDoc doc;
  245. if (p_dict.has("name")) {
  246. doc.name = p_dict["name"];
  247. }
  248. if (p_dict.has("value")) {
  249. doc.value = p_dict["value"];
  250. }
  251. if (p_dict.has("is_value_valid")) {
  252. doc.is_value_valid = p_dict["is_value_valid"];
  253. }
  254. if (p_dict.has("type")) {
  255. doc.type = p_dict["type"];
  256. }
  257. if (p_dict.has("enumeration")) {
  258. doc.enumeration = p_dict["enumeration"];
  259. if (p_dict.has("is_bitfield")) {
  260. doc.is_bitfield = p_dict["is_bitfield"];
  261. }
  262. }
  263. if (p_dict.has("description")) {
  264. doc.description = p_dict["description"];
  265. }
  266. #ifndef DISABLE_DEPRECATED
  267. if (p_dict.has("is_deprecated")) {
  268. doc.is_deprecated = p_dict["is_deprecated"];
  269. }
  270. if (p_dict.has("is_experimental")) {
  271. doc.is_experimental = p_dict["is_experimental"];
  272. }
  273. #endif
  274. if (p_dict.has("deprecated")) {
  275. doc.is_deprecated = true;
  276. doc.deprecated_message = p_dict["deprecated"];
  277. }
  278. if (p_dict.has("experimental")) {
  279. doc.is_experimental = true;
  280. doc.experimental_message = p_dict["experimental"];
  281. }
  282. if (p_dict.has("keywords")) {
  283. doc.keywords = p_dict["keywords"];
  284. }
  285. return doc;
  286. }
  287. static Dictionary to_dict(const ConstantDoc &p_doc) {
  288. Dictionary dict;
  289. if (!p_doc.name.is_empty()) {
  290. dict["name"] = p_doc.name;
  291. }
  292. if (!p_doc.value.is_empty()) {
  293. dict["value"] = p_doc.value;
  294. }
  295. dict["is_value_valid"] = p_doc.is_value_valid;
  296. dict["type"] = p_doc.type;
  297. if (!p_doc.enumeration.is_empty()) {
  298. dict["enumeration"] = p_doc.enumeration;
  299. dict["is_bitfield"] = p_doc.is_bitfield;
  300. }
  301. if (!p_doc.description.is_empty()) {
  302. dict["description"] = p_doc.description;
  303. }
  304. if (p_doc.is_deprecated) {
  305. dict["deprecated"] = p_doc.deprecated_message;
  306. }
  307. if (p_doc.is_experimental) {
  308. dict["experimental"] = p_doc.experimental_message;
  309. }
  310. if (!p_doc.keywords.is_empty()) {
  311. dict["keywords"] = p_doc.keywords;
  312. }
  313. return dict;
  314. }
  315. };
  316. struct PropertyDoc {
  317. String name;
  318. String type;
  319. String enumeration;
  320. bool is_bitfield = false;
  321. String description;
  322. String setter, getter;
  323. String default_value;
  324. bool overridden = false;
  325. String overrides;
  326. bool is_deprecated = false;
  327. String deprecated_message;
  328. bool is_experimental = false;
  329. String experimental_message;
  330. String keywords;
  331. bool operator<(const PropertyDoc &p_prop) const {
  332. return name.naturalcasecmp_to(p_prop.name) < 0;
  333. }
  334. static PropertyDoc from_dict(const Dictionary &p_dict) {
  335. PropertyDoc doc;
  336. if (p_dict.has("name")) {
  337. doc.name = p_dict["name"];
  338. }
  339. if (p_dict.has("type")) {
  340. doc.type = p_dict["type"];
  341. }
  342. if (p_dict.has("enumeration")) {
  343. doc.enumeration = p_dict["enumeration"];
  344. if (p_dict.has("is_bitfield")) {
  345. doc.is_bitfield = p_dict["is_bitfield"];
  346. }
  347. }
  348. if (p_dict.has("description")) {
  349. doc.description = p_dict["description"];
  350. }
  351. if (p_dict.has("setter")) {
  352. doc.setter = p_dict["setter"];
  353. }
  354. if (p_dict.has("getter")) {
  355. doc.getter = p_dict["getter"];
  356. }
  357. if (p_dict.has("default_value")) {
  358. doc.default_value = p_dict["default_value"];
  359. }
  360. if (p_dict.has("overridden")) {
  361. doc.overridden = p_dict["overridden"];
  362. }
  363. if (p_dict.has("overrides")) {
  364. doc.overrides = p_dict["overrides"];
  365. }
  366. #ifndef DISABLE_DEPRECATED
  367. if (p_dict.has("is_deprecated")) {
  368. doc.is_deprecated = p_dict["is_deprecated"];
  369. }
  370. if (p_dict.has("is_experimental")) {
  371. doc.is_experimental = p_dict["is_experimental"];
  372. }
  373. #endif
  374. if (p_dict.has("deprecated")) {
  375. doc.is_deprecated = true;
  376. doc.deprecated_message = p_dict["deprecated"];
  377. }
  378. if (p_dict.has("experimental")) {
  379. doc.is_experimental = true;
  380. doc.experimental_message = p_dict["experimental"];
  381. }
  382. if (p_dict.has("keywords")) {
  383. doc.keywords = p_dict["keywords"];
  384. }
  385. return doc;
  386. }
  387. static Dictionary to_dict(const PropertyDoc &p_doc) {
  388. Dictionary dict;
  389. if (!p_doc.name.is_empty()) {
  390. dict["name"] = p_doc.name;
  391. }
  392. if (!p_doc.type.is_empty()) {
  393. dict["type"] = p_doc.type;
  394. }
  395. if (!p_doc.enumeration.is_empty()) {
  396. dict["enumeration"] = p_doc.enumeration;
  397. dict["is_bitfield"] = p_doc.is_bitfield;
  398. }
  399. if (!p_doc.description.is_empty()) {
  400. dict["description"] = p_doc.description;
  401. }
  402. if (!p_doc.setter.is_empty()) {
  403. dict["setter"] = p_doc.setter;
  404. }
  405. if (!p_doc.getter.is_empty()) {
  406. dict["getter"] = p_doc.getter;
  407. }
  408. if (!p_doc.default_value.is_empty()) {
  409. dict["default_value"] = p_doc.default_value;
  410. }
  411. dict["overridden"] = p_doc.overridden;
  412. if (!p_doc.overrides.is_empty()) {
  413. dict["overrides"] = p_doc.overrides;
  414. }
  415. if (p_doc.is_deprecated) {
  416. dict["deprecated"] = p_doc.deprecated_message;
  417. }
  418. if (p_doc.is_experimental) {
  419. dict["experimental"] = p_doc.experimental_message;
  420. }
  421. if (!p_doc.keywords.is_empty()) {
  422. dict["keywords"] = p_doc.keywords;
  423. }
  424. return dict;
  425. }
  426. };
  427. struct ThemeItemDoc {
  428. String name;
  429. String type;
  430. String data_type;
  431. String description;
  432. bool is_deprecated = false;
  433. String deprecated_message;
  434. bool is_experimental = false;
  435. String experimental_message;
  436. String default_value;
  437. String keywords;
  438. bool operator<(const ThemeItemDoc &p_theme_item) const {
  439. // First sort by the data type, then by name.
  440. if (data_type == p_theme_item.data_type) {
  441. return name.naturalcasecmp_to(p_theme_item.name) < 0;
  442. }
  443. return data_type < p_theme_item.data_type;
  444. }
  445. static ThemeItemDoc from_dict(const Dictionary &p_dict) {
  446. ThemeItemDoc doc;
  447. if (p_dict.has("name")) {
  448. doc.name = p_dict["name"];
  449. }
  450. if (p_dict.has("type")) {
  451. doc.type = p_dict["type"];
  452. }
  453. if (p_dict.has("data_type")) {
  454. doc.data_type = p_dict["data_type"];
  455. }
  456. if (p_dict.has("description")) {
  457. doc.description = p_dict["description"];
  458. }
  459. if (p_dict.has("deprecated")) {
  460. doc.is_deprecated = true;
  461. doc.deprecated_message = p_dict["deprecated"];
  462. }
  463. if (p_dict.has("experimental")) {
  464. doc.is_experimental = true;
  465. doc.experimental_message = p_dict["experimental"];
  466. }
  467. if (p_dict.has("default_value")) {
  468. doc.default_value = p_dict["default_value"];
  469. }
  470. if (p_dict.has("keywords")) {
  471. doc.keywords = p_dict["keywords"];
  472. }
  473. return doc;
  474. }
  475. static Dictionary to_dict(const ThemeItemDoc &p_doc) {
  476. Dictionary dict;
  477. if (!p_doc.name.is_empty()) {
  478. dict["name"] = p_doc.name;
  479. }
  480. if (!p_doc.type.is_empty()) {
  481. dict["type"] = p_doc.type;
  482. }
  483. if (!p_doc.data_type.is_empty()) {
  484. dict["data_type"] = p_doc.data_type;
  485. }
  486. if (!p_doc.description.is_empty()) {
  487. dict["description"] = p_doc.description;
  488. }
  489. if (p_doc.is_deprecated) {
  490. dict["deprecated"] = p_doc.deprecated_message;
  491. }
  492. if (p_doc.is_experimental) {
  493. dict["experimental"] = p_doc.experimental_message;
  494. }
  495. if (!p_doc.default_value.is_empty()) {
  496. dict["default_value"] = p_doc.default_value;
  497. }
  498. if (!p_doc.keywords.is_empty()) {
  499. dict["keywords"] = p_doc.keywords;
  500. }
  501. return dict;
  502. }
  503. };
  504. struct TutorialDoc {
  505. String link;
  506. String title;
  507. static TutorialDoc from_dict(const Dictionary &p_dict) {
  508. TutorialDoc doc;
  509. if (p_dict.has("link")) {
  510. doc.link = p_dict["link"];
  511. }
  512. if (p_dict.has("title")) {
  513. doc.title = p_dict["title"];
  514. }
  515. return doc;
  516. }
  517. static Dictionary to_dict(const TutorialDoc &p_doc) {
  518. Dictionary dict;
  519. if (!p_doc.link.is_empty()) {
  520. dict["link"] = p_doc.link;
  521. }
  522. if (!p_doc.title.is_empty()) {
  523. dict["title"] = p_doc.title;
  524. }
  525. return dict;
  526. }
  527. };
  528. struct EnumDoc {
  529. String description;
  530. bool is_deprecated = false;
  531. String deprecated_message;
  532. bool is_experimental = false;
  533. String experimental_message;
  534. static EnumDoc from_dict(const Dictionary &p_dict) {
  535. EnumDoc doc;
  536. if (p_dict.has("description")) {
  537. doc.description = p_dict["description"];
  538. }
  539. #ifndef DISABLE_DEPRECATED
  540. if (p_dict.has("is_deprecated")) {
  541. doc.is_deprecated = p_dict["is_deprecated"];
  542. }
  543. if (p_dict.has("is_experimental")) {
  544. doc.is_experimental = p_dict["is_experimental"];
  545. }
  546. #endif
  547. if (p_dict.has("deprecated")) {
  548. doc.is_deprecated = true;
  549. doc.deprecated_message = p_dict["deprecated"];
  550. }
  551. if (p_dict.has("experimental")) {
  552. doc.is_experimental = true;
  553. doc.experimental_message = p_dict["experimental"];
  554. }
  555. return doc;
  556. }
  557. static Dictionary to_dict(const EnumDoc &p_doc) {
  558. Dictionary dict;
  559. if (!p_doc.description.is_empty()) {
  560. dict["description"] = p_doc.description;
  561. }
  562. if (p_doc.is_deprecated) {
  563. dict["deprecated"] = p_doc.deprecated_message;
  564. }
  565. if (p_doc.is_experimental) {
  566. dict["experimental"] = p_doc.experimental_message;
  567. }
  568. return dict;
  569. }
  570. };
  571. struct ClassDoc {
  572. String name;
  573. String inherits;
  574. String brief_description;
  575. String description;
  576. String keywords;
  577. Vector<TutorialDoc> tutorials;
  578. Vector<MethodDoc> constructors;
  579. Vector<MethodDoc> methods;
  580. Vector<MethodDoc> operators;
  581. Vector<MethodDoc> signals;
  582. Vector<ConstantDoc> constants;
  583. HashMap<String, EnumDoc> enums;
  584. Vector<PropertyDoc> properties;
  585. Vector<MethodDoc> annotations;
  586. Vector<ThemeItemDoc> theme_properties;
  587. bool is_deprecated = false;
  588. String deprecated_message;
  589. bool is_experimental = false;
  590. String experimental_message;
  591. bool is_script_doc = false;
  592. String script_path;
  593. bool operator<(const ClassDoc &p_class) const {
  594. return name < p_class.name;
  595. }
  596. static ClassDoc from_dict(const Dictionary &p_dict) {
  597. ClassDoc doc;
  598. if (p_dict.has("name")) {
  599. doc.name = p_dict["name"];
  600. }
  601. if (p_dict.has("inherits")) {
  602. doc.inherits = p_dict["inherits"];
  603. }
  604. if (p_dict.has("brief_description")) {
  605. doc.brief_description = p_dict["brief_description"];
  606. }
  607. if (p_dict.has("description")) {
  608. doc.description = p_dict["description"];
  609. }
  610. if (p_dict.has("keywords")) {
  611. doc.keywords = p_dict["keywords"];
  612. }
  613. Array tutorials;
  614. if (p_dict.has("tutorials")) {
  615. tutorials = p_dict["tutorials"];
  616. }
  617. for (int i = 0; i < tutorials.size(); i++) {
  618. doc.tutorials.push_back(TutorialDoc::from_dict(tutorials[i]));
  619. }
  620. Array constructors;
  621. if (p_dict.has("constructors")) {
  622. constructors = p_dict["constructors"];
  623. }
  624. for (int i = 0; i < constructors.size(); i++) {
  625. doc.constructors.push_back(MethodDoc::from_dict(constructors[i]));
  626. }
  627. Array methods;
  628. if (p_dict.has("methods")) {
  629. methods = p_dict["methods"];
  630. }
  631. for (int i = 0; i < methods.size(); i++) {
  632. doc.methods.push_back(MethodDoc::from_dict(methods[i]));
  633. }
  634. Array operators;
  635. if (p_dict.has("operators")) {
  636. operators = p_dict["operators"];
  637. }
  638. for (int i = 0; i < operators.size(); i++) {
  639. doc.operators.push_back(MethodDoc::from_dict(operators[i]));
  640. }
  641. Array signals;
  642. if (p_dict.has("signals")) {
  643. signals = p_dict["signals"];
  644. }
  645. for (int i = 0; i < signals.size(); i++) {
  646. doc.signals.push_back(MethodDoc::from_dict(signals[i]));
  647. }
  648. Array constants;
  649. if (p_dict.has("constants")) {
  650. constants = p_dict["constants"];
  651. }
  652. for (int i = 0; i < constants.size(); i++) {
  653. doc.constants.push_back(ConstantDoc::from_dict(constants[i]));
  654. }
  655. Dictionary enums;
  656. if (p_dict.has("enums")) {
  657. enums = p_dict["enums"];
  658. }
  659. for (const KeyValue<Variant, Variant> &kv : enums) {
  660. doc.enums[kv.key] = EnumDoc::from_dict(kv.value);
  661. }
  662. Array properties;
  663. if (p_dict.has("properties")) {
  664. properties = p_dict["properties"];
  665. }
  666. for (int i = 0; i < properties.size(); i++) {
  667. doc.properties.push_back(PropertyDoc::from_dict(properties[i]));
  668. }
  669. Array annotations;
  670. if (p_dict.has("annotations")) {
  671. annotations = p_dict["annotations"];
  672. }
  673. for (int i = 0; i < annotations.size(); i++) {
  674. doc.annotations.push_back(MethodDoc::from_dict(annotations[i]));
  675. }
  676. Array theme_properties;
  677. if (p_dict.has("theme_properties")) {
  678. theme_properties = p_dict["theme_properties"];
  679. }
  680. for (int i = 0; i < theme_properties.size(); i++) {
  681. doc.theme_properties.push_back(ThemeItemDoc::from_dict(theme_properties[i]));
  682. }
  683. #ifndef DISABLE_DEPRECATED
  684. if (p_dict.has("is_deprecated")) {
  685. doc.is_deprecated = p_dict["is_deprecated"];
  686. }
  687. if (p_dict.has("is_experimental")) {
  688. doc.is_experimental = p_dict["is_experimental"];
  689. }
  690. #endif
  691. if (p_dict.has("deprecated")) {
  692. doc.is_deprecated = true;
  693. doc.deprecated_message = p_dict["deprecated"];
  694. }
  695. if (p_dict.has("experimental")) {
  696. doc.is_experimental = true;
  697. doc.experimental_message = p_dict["experimental"];
  698. }
  699. if (p_dict.has("is_script_doc")) {
  700. doc.is_script_doc = p_dict["is_script_doc"];
  701. }
  702. if (p_dict.has("script_path")) {
  703. doc.script_path = p_dict["script_path"];
  704. }
  705. return doc;
  706. }
  707. static Dictionary to_dict(const ClassDoc &p_doc) {
  708. Dictionary dict;
  709. if (!p_doc.name.is_empty()) {
  710. dict["name"] = p_doc.name;
  711. }
  712. if (!p_doc.inherits.is_empty()) {
  713. dict["inherits"] = p_doc.inherits;
  714. }
  715. if (!p_doc.brief_description.is_empty()) {
  716. dict["brief_description"] = p_doc.brief_description;
  717. }
  718. if (!p_doc.description.is_empty()) {
  719. dict["description"] = p_doc.description;
  720. }
  721. if (!p_doc.tutorials.is_empty()) {
  722. Array tutorials;
  723. for (int i = 0; i < p_doc.tutorials.size(); i++) {
  724. tutorials.push_back(TutorialDoc::to_dict(p_doc.tutorials[i]));
  725. }
  726. dict["tutorials"] = tutorials;
  727. }
  728. if (!p_doc.constructors.is_empty()) {
  729. Array constructors;
  730. for (int i = 0; i < p_doc.constructors.size(); i++) {
  731. constructors.push_back(MethodDoc::to_dict(p_doc.constructors[i]));
  732. }
  733. dict["constructors"] = constructors;
  734. }
  735. if (!p_doc.methods.is_empty()) {
  736. Array methods;
  737. for (int i = 0; i < p_doc.methods.size(); i++) {
  738. methods.push_back(MethodDoc::to_dict(p_doc.methods[i]));
  739. }
  740. dict["methods"] = methods;
  741. }
  742. if (!p_doc.operators.is_empty()) {
  743. Array operators;
  744. for (int i = 0; i < p_doc.operators.size(); i++) {
  745. operators.push_back(MethodDoc::to_dict(p_doc.operators[i]));
  746. }
  747. dict["operators"] = operators;
  748. }
  749. if (!p_doc.signals.is_empty()) {
  750. Array signals;
  751. for (int i = 0; i < p_doc.signals.size(); i++) {
  752. signals.push_back(MethodDoc::to_dict(p_doc.signals[i]));
  753. }
  754. dict["signals"] = signals;
  755. }
  756. if (!p_doc.constants.is_empty()) {
  757. Array constants;
  758. for (int i = 0; i < p_doc.constants.size(); i++) {
  759. constants.push_back(ConstantDoc::to_dict(p_doc.constants[i]));
  760. }
  761. dict["constants"] = constants;
  762. }
  763. if (!p_doc.enums.is_empty()) {
  764. Dictionary enums;
  765. for (const KeyValue<String, EnumDoc> &E : p_doc.enums) {
  766. enums[E.key] = EnumDoc::to_dict(E.value);
  767. }
  768. dict["enums"] = enums;
  769. }
  770. if (!p_doc.properties.is_empty()) {
  771. Array properties;
  772. for (int i = 0; i < p_doc.properties.size(); i++) {
  773. properties.push_back(PropertyDoc::to_dict(p_doc.properties[i]));
  774. }
  775. dict["properties"] = properties;
  776. }
  777. if (!p_doc.annotations.is_empty()) {
  778. Array annotations;
  779. for (int i = 0; i < p_doc.annotations.size(); i++) {
  780. annotations.push_back(MethodDoc::to_dict(p_doc.annotations[i]));
  781. }
  782. dict["annotations"] = annotations;
  783. }
  784. if (!p_doc.theme_properties.is_empty()) {
  785. Array theme_properties;
  786. for (int i = 0; i < p_doc.theme_properties.size(); i++) {
  787. theme_properties.push_back(ThemeItemDoc::to_dict(p_doc.theme_properties[i]));
  788. }
  789. dict["theme_properties"] = theme_properties;
  790. }
  791. if (p_doc.is_deprecated) {
  792. dict["deprecated"] = p_doc.deprecated_message;
  793. }
  794. if (p_doc.is_experimental) {
  795. dict["experimental"] = p_doc.experimental_message;
  796. }
  797. dict["is_script_doc"] = p_doc.is_script_doc;
  798. if (!p_doc.script_path.is_empty()) {
  799. dict["script_path"] = p_doc.script_path;
  800. }
  801. if (!p_doc.keywords.is_empty()) {
  802. dict["keywords"] = p_doc.keywords;
  803. }
  804. return dict;
  805. }
  806. };
  807. static String get_default_value_string(const Variant &p_value);
  808. static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo);
  809. static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo);
  810. static void method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc);
  811. };