doc_data.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. /*************************************************************************/
  2. /* doc_data.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. #include "doc_data.h"
  31. #include "core/engine.h"
  32. #include "core/global_constants.h"
  33. #include "core/io/compression.h"
  34. #include "core/io/marshalls.h"
  35. #include "core/os/dir_access.h"
  36. #include "core/project_settings.h"
  37. #include "core/script_language.h"
  38. #include "core/version.h"
  39. #include "scene/resources/theme.h"
  40. void DocData::merge_from(const DocData &p_data) {
  41. for (Map<String, ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
  42. ClassDoc &c = E->get();
  43. if (!p_data.class_list.has(c.name)) {
  44. continue;
  45. }
  46. const ClassDoc &cf = p_data.class_list[c.name];
  47. c.description = cf.description;
  48. c.brief_description = cf.brief_description;
  49. c.tutorials = cf.tutorials;
  50. for (int i = 0; i < c.methods.size(); i++) {
  51. MethodDoc &m = c.methods.write[i];
  52. for (int j = 0; j < cf.methods.size(); j++) {
  53. if (cf.methods[j].name != m.name) {
  54. continue;
  55. }
  56. if (cf.methods[j].arguments.size() != m.arguments.size()) {
  57. continue;
  58. }
  59. // since polymorphic functions are allowed we need to check the type of
  60. // the arguments so we make sure they are different.
  61. int arg_count = cf.methods[j].arguments.size();
  62. Vector<bool> arg_used;
  63. arg_used.resize(arg_count);
  64. for (int l = 0; l < arg_count; ++l) {
  65. arg_used.write[l] = false;
  66. }
  67. // also there is no guarantee that argument ordering will match, so we
  68. // have to check one by one so we make sure we have an exact match
  69. for (int k = 0; k < arg_count; ++k) {
  70. for (int l = 0; l < arg_count; ++l) {
  71. if (cf.methods[j].arguments[k].type == m.arguments[l].type && !arg_used[l]) {
  72. arg_used.write[l] = true;
  73. break;
  74. }
  75. }
  76. }
  77. bool not_the_same = false;
  78. for (int l = 0; l < arg_count; ++l) {
  79. if (!arg_used[l]) { // at least one of the arguments was different
  80. not_the_same = true;
  81. }
  82. }
  83. if (not_the_same) {
  84. continue;
  85. }
  86. const MethodDoc &mf = cf.methods[j];
  87. m.description = mf.description;
  88. break;
  89. }
  90. }
  91. for (int i = 0; i < c.signals.size(); i++) {
  92. MethodDoc &m = c.signals.write[i];
  93. for (int j = 0; j < cf.signals.size(); j++) {
  94. if (cf.signals[j].name != m.name) {
  95. continue;
  96. }
  97. const MethodDoc &mf = cf.signals[j];
  98. m.description = mf.description;
  99. break;
  100. }
  101. }
  102. for (int i = 0; i < c.constants.size(); i++) {
  103. ConstantDoc &m = c.constants.write[i];
  104. for (int j = 0; j < cf.constants.size(); j++) {
  105. if (cf.constants[j].name != m.name) {
  106. continue;
  107. }
  108. const ConstantDoc &mf = cf.constants[j];
  109. m.description = mf.description;
  110. break;
  111. }
  112. }
  113. for (int i = 0; i < c.properties.size(); i++) {
  114. PropertyDoc &p = c.properties.write[i];
  115. for (int j = 0; j < cf.properties.size(); j++) {
  116. if (cf.properties[j].name != p.name) {
  117. continue;
  118. }
  119. const PropertyDoc &pf = cf.properties[j];
  120. p.description = pf.description;
  121. break;
  122. }
  123. }
  124. for (int i = 0; i < c.theme_properties.size(); i++) {
  125. ThemeItemDoc &ti = c.theme_properties.write[i];
  126. for (int j = 0; j < cf.theme_properties.size(); j++) {
  127. if (cf.theme_properties[j].name != ti.name || cf.theme_properties[j].data_type != ti.data_type) {
  128. continue;
  129. }
  130. const ThemeItemDoc &pf = cf.theme_properties[j];
  131. ti.description = pf.description;
  132. break;
  133. }
  134. }
  135. }
  136. }
  137. void DocData::remove_from(const DocData &p_data) {
  138. for (Map<String, ClassDoc>::Element *E = p_data.class_list.front(); E; E = E->next()) {
  139. if (class_list.has(E->key())) {
  140. class_list.erase(E->key());
  141. }
  142. }
  143. }
  144. static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo) {
  145. if (p_retinfo.type == Variant::INT && p_retinfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
  146. p_method.return_enum = p_retinfo.class_name;
  147. if (p_method.return_enum.begins_with("_")) { //proxy class
  148. p_method.return_enum = p_method.return_enum.substr(1, p_method.return_enum.length());
  149. }
  150. p_method.return_type = "int";
  151. } else if (p_retinfo.class_name != StringName()) {
  152. p_method.return_type = p_retinfo.class_name;
  153. } else if (p_retinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
  154. p_method.return_type = p_retinfo.hint_string;
  155. } else if (p_retinfo.type == Variant::NIL && p_retinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
  156. p_method.return_type = "Variant";
  157. } else if (p_retinfo.type == Variant::NIL) {
  158. p_method.return_type = "void";
  159. } else {
  160. p_method.return_type = Variant::get_type_name(p_retinfo.type);
  161. }
  162. }
  163. static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo) {
  164. p_argument.name = p_arginfo.name;
  165. if (p_arginfo.type == Variant::INT && p_arginfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
  166. p_argument.enumeration = p_arginfo.class_name;
  167. if (p_argument.enumeration.begins_with("_")) { //proxy class
  168. p_argument.enumeration = p_argument.enumeration.substr(1, p_argument.enumeration.length());
  169. }
  170. p_argument.type = "int";
  171. } else if (p_arginfo.class_name != StringName()) {
  172. p_argument.type = p_arginfo.class_name;
  173. } else if (p_arginfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
  174. p_argument.type = p_arginfo.hint_string;
  175. } else if (p_arginfo.type == Variant::NIL) {
  176. // Parameters cannot be void, so PROPERTY_USAGE_NIL_IS_VARIANT is not necessary
  177. p_argument.type = "Variant";
  178. } else {
  179. p_argument.type = Variant::get_type_name(p_arginfo.type);
  180. }
  181. }
  182. static Variant get_documentation_default_value(const StringName &p_class_name, const StringName &p_property_name, bool &r_default_value_valid) {
  183. Variant default_value = Variant();
  184. r_default_value_valid = false;
  185. if (ClassDB::can_instance(p_class_name)) {
  186. default_value = ClassDB::class_get_default_property_value(p_class_name, p_property_name, &r_default_value_valid);
  187. } else {
  188. // Cannot get default value of classes that can't be instanced
  189. List<StringName> inheriting_classes;
  190. ClassDB::get_direct_inheriters_from_class(p_class_name, &inheriting_classes);
  191. for (List<StringName>::Element *E2 = inheriting_classes.front(); E2; E2 = E2->next()) {
  192. if (ClassDB::can_instance(E2->get())) {
  193. default_value = ClassDB::class_get_default_property_value(E2->get(), p_property_name, &r_default_value_valid);
  194. if (r_default_value_valid) {
  195. break;
  196. }
  197. }
  198. }
  199. }
  200. return default_value;
  201. }
  202. void DocData::generate(bool p_basic_types) {
  203. List<StringName> classes;
  204. ClassDB::get_class_list(&classes);
  205. classes.sort_custom<StringName::AlphCompare>();
  206. // Move ProjectSettings, so that other classes can register properties there.
  207. classes.move_to_back(classes.find("ProjectSettings"));
  208. bool skip_setter_getter_methods = true;
  209. while (classes.size()) {
  210. Set<StringName> setters_getters;
  211. String name = classes.front()->get();
  212. if (!ClassDB::is_class_exposed(name)) {
  213. print_verbose(vformat("Class '%s' is not exposed, skipping.", name));
  214. classes.pop_front();
  215. continue;
  216. }
  217. String cname = name;
  218. if (cname.begins_with("_")) { //proxy class
  219. cname = cname.substr(1, name.length());
  220. }
  221. class_list[cname] = ClassDoc();
  222. ClassDoc &c = class_list[cname];
  223. c.name = cname;
  224. c.inherits = ClassDB::get_parent_class(name);
  225. List<PropertyInfo> properties;
  226. List<PropertyInfo> own_properties;
  227. if (name == "ProjectSettings") {
  228. //special case for project settings, so settings can be documented
  229. ProjectSettings::get_singleton()->get_property_list(&properties);
  230. own_properties = properties;
  231. } else {
  232. ClassDB::get_property_list(name, &properties);
  233. ClassDB::get_property_list(name, &own_properties, true);
  234. }
  235. List<PropertyInfo>::Element *EO = own_properties.front();
  236. for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
  237. bool inherited = EO == nullptr;
  238. if (EO && EO->get() == E->get()) {
  239. inherited = false;
  240. EO = EO->next();
  241. }
  242. if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL) {
  243. continue;
  244. }
  245. PropertyDoc prop;
  246. prop.name = E->get().name;
  247. prop.overridden = inherited;
  248. bool default_value_valid = false;
  249. Variant default_value;
  250. if (name == "ProjectSettings") {
  251. // Special case for project settings, so that settings are not taken from the current project's settings
  252. if (E->get().name == "script" ||
  253. ProjectSettings::get_singleton()->get_order(E->get().name) >= ProjectSettings::NO_BUILTIN_ORDER_BASE) {
  254. continue;
  255. }
  256. if (E->get().usage & PROPERTY_USAGE_EDITOR) {
  257. default_value = ProjectSettings::get_singleton()->property_get_revert(E->get().name);
  258. default_value_valid = true;
  259. }
  260. } else {
  261. default_value = get_documentation_default_value(name, E->get().name, default_value_valid);
  262. if (inherited) {
  263. bool base_default_value_valid = false;
  264. Variant base_default_value = get_documentation_default_value(ClassDB::get_parent_class(name), E->get().name, base_default_value_valid);
  265. if (!default_value_valid || !base_default_value_valid || default_value == base_default_value) {
  266. continue;
  267. }
  268. }
  269. }
  270. if (default_value_valid && default_value.get_type() != Variant::OBJECT) {
  271. prop.default_value = default_value.get_construct_string().replace("\n", "");
  272. }
  273. StringName setter = ClassDB::get_property_setter(name, E->get().name);
  274. StringName getter = ClassDB::get_property_getter(name, E->get().name);
  275. prop.setter = setter;
  276. prop.getter = getter;
  277. bool found_type = false;
  278. if (getter != StringName()) {
  279. MethodBind *mb = ClassDB::get_method(name, getter);
  280. if (mb) {
  281. PropertyInfo retinfo = mb->get_return_info();
  282. found_type = true;
  283. if (retinfo.type == Variant::INT && retinfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
  284. prop.enumeration = retinfo.class_name;
  285. prop.type = "int";
  286. } else if (retinfo.class_name != StringName()) {
  287. prop.type = retinfo.class_name;
  288. } else if (retinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
  289. prop.type = retinfo.hint_string;
  290. } else if (retinfo.type == Variant::NIL && retinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
  291. prop.type = "Variant";
  292. } else if (retinfo.type == Variant::NIL) {
  293. prop.type = "void";
  294. } else {
  295. prop.type = Variant::get_type_name(retinfo.type);
  296. }
  297. }
  298. setters_getters.insert(getter);
  299. }
  300. if (setter != StringName()) {
  301. setters_getters.insert(setter);
  302. }
  303. if (!found_type) {
  304. if (E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE) {
  305. prop.type = E->get().hint_string;
  306. } else {
  307. prop.type = Variant::get_type_name(E->get().type);
  308. }
  309. }
  310. c.properties.push_back(prop);
  311. }
  312. List<MethodInfo> method_list;
  313. ClassDB::get_method_list(name, &method_list, true);
  314. method_list.sort();
  315. for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) {
  316. if (E->get().name == "" || (E->get().name[0] == '_' && !(E->get().flags & METHOD_FLAG_VIRTUAL))) {
  317. continue; //hidden, don't count
  318. }
  319. if (skip_setter_getter_methods && setters_getters.has(E->get().name)) {
  320. // Don't skip parametric setters and getters, i.e. method which require
  321. // one or more parameters to define what property should be set or retrieved.
  322. // E.g. CPUParticles::set_param(Parameter param, float value).
  323. if (E->get().arguments.size() == 0 /* getter */ || (E->get().arguments.size() == 1 && E->get().return_val.type == Variant::NIL /* setter */)) {
  324. continue;
  325. }
  326. }
  327. MethodDoc method;
  328. method.name = E->get().name;
  329. if (E->get().flags & METHOD_FLAG_VIRTUAL) {
  330. method.qualifiers = "virtual";
  331. }
  332. if (E->get().flags & METHOD_FLAG_CONST) {
  333. if (method.qualifiers != "") {
  334. method.qualifiers += " ";
  335. }
  336. method.qualifiers += "const";
  337. } else if (E->get().flags & METHOD_FLAG_VARARG) {
  338. if (method.qualifiers != "") {
  339. method.qualifiers += " ";
  340. }
  341. method.qualifiers += "vararg";
  342. }
  343. for (int i = -1; i < E->get().arguments.size(); i++) {
  344. if (i == -1) {
  345. #ifdef DEBUG_METHODS_ENABLED
  346. return_doc_from_retinfo(method, E->get().return_val);
  347. #endif
  348. } else {
  349. const PropertyInfo &arginfo = E->get().arguments[i];
  350. ArgumentDoc argument;
  351. argument_doc_from_arginfo(argument, arginfo);
  352. int darg_idx = i - (E->get().arguments.size() - E->get().default_arguments.size());
  353. if (darg_idx >= 0) {
  354. Variant default_arg = E->get().default_arguments[darg_idx];
  355. argument.default_value = default_arg.get_construct_string();
  356. }
  357. method.arguments.push_back(argument);
  358. }
  359. }
  360. c.methods.push_back(method);
  361. }
  362. List<MethodInfo> signal_list;
  363. ClassDB::get_signal_list(name, &signal_list, true);
  364. if (signal_list.size()) {
  365. for (List<MethodInfo>::Element *EV = signal_list.front(); EV; EV = EV->next()) {
  366. MethodDoc signal;
  367. signal.name = EV->get().name;
  368. for (int i = 0; i < EV->get().arguments.size(); i++) {
  369. const PropertyInfo &arginfo = EV->get().arguments[i];
  370. ArgumentDoc argument;
  371. argument_doc_from_arginfo(argument, arginfo);
  372. signal.arguments.push_back(argument);
  373. }
  374. c.signals.push_back(signal);
  375. }
  376. }
  377. List<String> constant_list;
  378. ClassDB::get_integer_constant_list(name, &constant_list, true);
  379. for (List<String>::Element *E = constant_list.front(); E; E = E->next()) {
  380. ConstantDoc constant;
  381. constant.name = E->get();
  382. constant.value = itos(ClassDB::get_integer_constant(name, E->get()));
  383. constant.enumeration = ClassDB::get_integer_constant_enum(name, E->get());
  384. c.constants.push_back(constant);
  385. }
  386. // Theme items.
  387. {
  388. List<StringName> l;
  389. Theme::get_default()->get_color_list(cname, &l);
  390. for (List<StringName>::Element *E = l.front(); E; E = E->next()) {
  391. ThemeItemDoc tid;
  392. tid.name = E->get();
  393. tid.type = "Color";
  394. tid.data_type = "color";
  395. tid.default_value = Variant(Theme::get_default()->get_color(E->get(), cname)).get_construct_string();
  396. c.theme_properties.push_back(tid);
  397. }
  398. l.clear();
  399. Theme::get_default()->get_constant_list(cname, &l);
  400. for (List<StringName>::Element *E = l.front(); E; E = E->next()) {
  401. ThemeItemDoc tid;
  402. tid.name = E->get();
  403. tid.type = "int";
  404. tid.data_type = "constant";
  405. tid.default_value = itos(Theme::get_default()->get_constant(E->get(), cname));
  406. c.theme_properties.push_back(tid);
  407. }
  408. l.clear();
  409. Theme::get_default()->get_font_list(cname, &l);
  410. for (List<StringName>::Element *E = l.front(); E; E = E->next()) {
  411. ThemeItemDoc tid;
  412. tid.name = E->get();
  413. tid.type = "Font";
  414. tid.data_type = "font";
  415. c.theme_properties.push_back(tid);
  416. }
  417. l.clear();
  418. Theme::get_default()->get_icon_list(cname, &l);
  419. for (List<StringName>::Element *E = l.front(); E; E = E->next()) {
  420. ThemeItemDoc tid;
  421. tid.name = E->get();
  422. tid.type = "Texture";
  423. tid.data_type = "icon";
  424. c.theme_properties.push_back(tid);
  425. }
  426. l.clear();
  427. Theme::get_default()->get_stylebox_list(cname, &l);
  428. for (List<StringName>::Element *E = l.front(); E; E = E->next()) {
  429. ThemeItemDoc tid;
  430. tid.name = E->get();
  431. tid.type = "StyleBox";
  432. tid.data_type = "style";
  433. c.theme_properties.push_back(tid);
  434. }
  435. }
  436. classes.pop_front();
  437. }
  438. {
  439. // So we can document the concept of Variant even if it's not a usable class per se.
  440. class_list["Variant"] = ClassDoc();
  441. class_list["Variant"].name = "Variant";
  442. }
  443. if (!p_basic_types) {
  444. return;
  445. }
  446. // Add Variant types.
  447. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  448. if (i == Variant::NIL) {
  449. continue; // Not exposed outside of 'null', should not be in class list.
  450. }
  451. if (i == Variant::OBJECT) {
  452. continue; // Use the core type instead.
  453. }
  454. String cname = Variant::get_type_name(Variant::Type(i));
  455. class_list[cname] = ClassDoc();
  456. ClassDoc &c = class_list[cname];
  457. c.name = cname;
  458. Variant::CallError cerror;
  459. Variant v = Variant::construct(Variant::Type(i), nullptr, 0, cerror);
  460. List<MethodInfo> method_list;
  461. v.get_method_list(&method_list);
  462. method_list.sort();
  463. Variant::get_constructor_list(Variant::Type(i), &method_list);
  464. for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) {
  465. MethodInfo &mi = E->get();
  466. MethodDoc method;
  467. method.name = mi.name;
  468. for (int j = 0; j < mi.arguments.size(); j++) {
  469. PropertyInfo arginfo = mi.arguments[j];
  470. ArgumentDoc ad;
  471. argument_doc_from_arginfo(ad, mi.arguments[j]);
  472. ad.name = arginfo.name;
  473. int darg_idx = mi.default_arguments.size() - mi.arguments.size() + j;
  474. if (darg_idx >= 0) {
  475. Variant default_arg = mi.default_arguments[darg_idx];
  476. ad.default_value = default_arg.get_construct_string();
  477. }
  478. method.arguments.push_back(ad);
  479. }
  480. if (mi.return_val.type == Variant::NIL) {
  481. if (mi.return_val.name != "") {
  482. method.return_type = "Variant";
  483. }
  484. } else {
  485. method.return_type = Variant::get_type_name(mi.return_val.type);
  486. }
  487. c.methods.push_back(method);
  488. }
  489. List<PropertyInfo> properties;
  490. v.get_property_list(&properties);
  491. for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
  492. PropertyInfo pi = E->get();
  493. PropertyDoc property;
  494. property.name = pi.name;
  495. property.type = Variant::get_type_name(pi.type);
  496. property.default_value = v.get(pi.name).get_construct_string();
  497. c.properties.push_back(property);
  498. }
  499. List<StringName> constants;
  500. Variant::get_constants_for_type(Variant::Type(i), &constants);
  501. for (List<StringName>::Element *E = constants.front(); E; E = E->next()) {
  502. ConstantDoc constant;
  503. constant.name = E->get();
  504. Variant value = Variant::get_constant_value(Variant::Type(i), E->get());
  505. constant.value = value.get_type() == Variant::INT ? itos(value) : value.get_construct_string();
  506. c.constants.push_back(constant);
  507. }
  508. }
  509. //built in constants and functions
  510. {
  511. String cname = "@GlobalScope";
  512. class_list[cname] = ClassDoc();
  513. ClassDoc &c = class_list[cname];
  514. c.name = cname;
  515. for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) {
  516. ConstantDoc cd;
  517. cd.name = GlobalConstants::get_global_constant_name(i);
  518. cd.value = itos(GlobalConstants::get_global_constant_value(i));
  519. cd.enumeration = GlobalConstants::get_global_constant_enum(i);
  520. c.constants.push_back(cd);
  521. }
  522. List<Engine::Singleton> singletons;
  523. Engine::get_singleton()->get_singletons(&singletons);
  524. //servers (this is kind of hackish)
  525. for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) {
  526. PropertyDoc pd;
  527. Engine::Singleton &s = E->get();
  528. if (!s.ptr) {
  529. continue;
  530. }
  531. pd.name = s.name;
  532. pd.type = s.ptr->get_class();
  533. while (String(ClassDB::get_parent_class(pd.type)) != "Object") {
  534. pd.type = ClassDB::get_parent_class(pd.type);
  535. }
  536. if (pd.type.begins_with("_")) {
  537. pd.type = pd.type.substr(1, pd.type.length());
  538. }
  539. c.properties.push_back(pd);
  540. }
  541. }
  542. // Built-in script reference.
  543. // We only add a doc entry for languages which actually define any built-in
  544. // methods or constants.
  545. {
  546. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  547. ScriptLanguage *lang = ScriptServer::get_language(i);
  548. String cname = "@" + lang->get_name();
  549. ClassDoc c;
  550. c.name = cname;
  551. // Get functions.
  552. List<MethodInfo> minfo;
  553. lang->get_public_functions(&minfo);
  554. for (List<MethodInfo>::Element *E = minfo.front(); E; E = E->next()) {
  555. MethodInfo &mi = E->get();
  556. MethodDoc md;
  557. md.name = mi.name;
  558. if (mi.flags & METHOD_FLAG_VARARG) {
  559. if (md.qualifiers != "") {
  560. md.qualifiers += " ";
  561. }
  562. md.qualifiers += "vararg";
  563. }
  564. return_doc_from_retinfo(md, mi.return_val);
  565. for (int j = 0; j < mi.arguments.size(); j++) {
  566. ArgumentDoc ad;
  567. argument_doc_from_arginfo(ad, mi.arguments[j]);
  568. int darg_idx = j - (mi.arguments.size() - mi.default_arguments.size());
  569. if (darg_idx >= 0) {
  570. Variant default_arg = E->get().default_arguments[darg_idx];
  571. ad.default_value = default_arg.get_construct_string();
  572. }
  573. md.arguments.push_back(ad);
  574. }
  575. c.methods.push_back(md);
  576. }
  577. // Get constants.
  578. List<Pair<String, Variant>> cinfo;
  579. lang->get_public_constants(&cinfo);
  580. for (List<Pair<String, Variant>>::Element *E = cinfo.front(); E; E = E->next()) {
  581. ConstantDoc cd;
  582. cd.name = E->get().first;
  583. cd.value = E->get().second;
  584. c.constants.push_back(cd);
  585. }
  586. // Skip adding the lang if it doesn't expose anything (e.g. C#).
  587. if (c.methods.empty() && c.constants.empty()) {
  588. continue;
  589. }
  590. class_list[cname] = c;
  591. }
  592. }
  593. }
  594. static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> &methods) {
  595. String section = parser->get_node_name();
  596. String element = section.substr(0, section.length() - 1);
  597. while (parser->read() == OK) {
  598. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  599. if (parser->get_node_name() == element) {
  600. DocData::MethodDoc method;
  601. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  602. method.name = parser->get_attribute_value("name");
  603. if (parser->has_attribute("qualifiers")) {
  604. method.qualifiers = parser->get_attribute_value("qualifiers");
  605. }
  606. while (parser->read() == OK) {
  607. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  608. String name = parser->get_node_name();
  609. if (name == "return") {
  610. ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
  611. method.return_type = parser->get_attribute_value("type");
  612. if (parser->has_attribute("enum")) {
  613. method.return_enum = parser->get_attribute_value("enum");
  614. }
  615. } else if (name == "argument") {
  616. DocData::ArgumentDoc argument;
  617. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  618. argument.name = parser->get_attribute_value("name");
  619. ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
  620. argument.type = parser->get_attribute_value("type");
  621. if (parser->has_attribute("enum")) {
  622. argument.enumeration = parser->get_attribute_value("enum");
  623. }
  624. method.arguments.push_back(argument);
  625. } else if (name == "description") {
  626. parser->read();
  627. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  628. method.description = parser->get_node_data();
  629. }
  630. }
  631. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == element) {
  632. break;
  633. }
  634. }
  635. methods.push_back(method);
  636. } else {
  637. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + parser->get_node_name() + ".");
  638. }
  639. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == section) {
  640. break;
  641. }
  642. }
  643. return OK;
  644. }
  645. Error DocData::load_classes(const String &p_dir) {
  646. Error err;
  647. DirAccessRef da = DirAccess::open(p_dir, &err);
  648. if (!da) {
  649. return err;
  650. }
  651. da->list_dir_begin();
  652. String path;
  653. path = da->get_next();
  654. while (path != String()) {
  655. if (!da->current_is_dir() && path.ends_with("xml")) {
  656. Ref<XMLParser> parser = memnew(XMLParser);
  657. Error err2 = parser->open(p_dir.plus_file(path));
  658. if (err2) {
  659. return err2;
  660. }
  661. _load(parser);
  662. }
  663. path = da->get_next();
  664. }
  665. da->list_dir_end();
  666. return OK;
  667. }
  668. Error DocData::erase_classes(const String &p_dir) {
  669. Error err;
  670. DirAccessRef da = DirAccess::open(p_dir, &err);
  671. if (!da) {
  672. return err;
  673. }
  674. List<String> to_erase;
  675. da->list_dir_begin();
  676. String path;
  677. path = da->get_next();
  678. while (path != String()) {
  679. if (!da->current_is_dir() && path.ends_with("xml")) {
  680. to_erase.push_back(path);
  681. }
  682. path = da->get_next();
  683. }
  684. da->list_dir_end();
  685. while (to_erase.size()) {
  686. da->remove(to_erase.front()->get());
  687. to_erase.pop_front();
  688. }
  689. return OK;
  690. }
  691. Error DocData::_load(Ref<XMLParser> parser) {
  692. Error err = OK;
  693. while ((err = parser->read()) == OK) {
  694. if (parser->get_node_type() == XMLParser::NODE_ELEMENT && parser->get_node_name() == "?xml") {
  695. parser->skip_section();
  696. }
  697. if (parser->get_node_type() != XMLParser::NODE_ELEMENT) {
  698. continue; //no idea what this may be, but skipping anyway
  699. }
  700. ERR_FAIL_COND_V(parser->get_node_name() != "class", ERR_FILE_CORRUPT);
  701. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  702. String name = parser->get_attribute_value("name");
  703. class_list[name] = ClassDoc();
  704. ClassDoc &c = class_list[name];
  705. c.name = name;
  706. if (parser->has_attribute("inherits")) {
  707. c.inherits = parser->get_attribute_value("inherits");
  708. }
  709. while (parser->read() == OK) {
  710. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  711. String name2 = parser->get_node_name();
  712. if (name2 == "brief_description") {
  713. parser->read();
  714. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  715. c.brief_description = parser->get_node_data();
  716. }
  717. } else if (name2 == "description") {
  718. parser->read();
  719. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  720. c.description = parser->get_node_data();
  721. }
  722. } else if (name2 == "tutorials") {
  723. while (parser->read() == OK) {
  724. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  725. String name3 = parser->get_node_name();
  726. if (name3 == "link") {
  727. TutorialDoc tutorial;
  728. if (parser->has_attribute("title")) {
  729. tutorial.title = parser->get_attribute_value("title");
  730. }
  731. parser->read();
  732. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  733. tutorial.link = parser->get_node_data().strip_edges();
  734. c.tutorials.push_back(tutorial);
  735. }
  736. } else {
  737. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
  738. }
  739. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "tutorials") {
  740. break; // End of <tutorials>.
  741. }
  742. }
  743. } else if (name2 == "methods") {
  744. Error err2 = _parse_methods(parser, c.methods);
  745. ERR_FAIL_COND_V(err2, err2);
  746. } else if (name2 == "signals") {
  747. Error err2 = _parse_methods(parser, c.signals);
  748. ERR_FAIL_COND_V(err2, err2);
  749. } else if (name2 == "members") {
  750. while (parser->read() == OK) {
  751. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  752. String name3 = parser->get_node_name();
  753. if (name3 == "member") {
  754. PropertyDoc prop2;
  755. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  756. prop2.name = parser->get_attribute_value("name");
  757. ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
  758. prop2.type = parser->get_attribute_value("type");
  759. if (parser->has_attribute("setter")) {
  760. prop2.setter = parser->get_attribute_value("setter");
  761. }
  762. if (parser->has_attribute("getter")) {
  763. prop2.getter = parser->get_attribute_value("getter");
  764. }
  765. if (parser->has_attribute("enum")) {
  766. prop2.enumeration = parser->get_attribute_value("enum");
  767. }
  768. if (!parser->is_empty()) {
  769. parser->read();
  770. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  771. prop2.description = parser->get_node_data();
  772. }
  773. }
  774. c.properties.push_back(prop2);
  775. } else {
  776. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
  777. }
  778. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "members") {
  779. break; // End of <members>.
  780. }
  781. }
  782. } else if (name2 == "theme_items") {
  783. while (parser->read() == OK) {
  784. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  785. String name3 = parser->get_node_name();
  786. if (name3 == "theme_item") {
  787. ThemeItemDoc prop2;
  788. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  789. prop2.name = parser->get_attribute_value("name");
  790. ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
  791. prop2.type = parser->get_attribute_value("type");
  792. ERR_FAIL_COND_V(!parser->has_attribute("data_type"), ERR_FILE_CORRUPT);
  793. prop2.data_type = parser->get_attribute_value("data_type");
  794. if (!parser->is_empty()) {
  795. parser->read();
  796. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  797. prop2.description = parser->get_node_data();
  798. }
  799. }
  800. c.theme_properties.push_back(prop2);
  801. } else {
  802. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
  803. }
  804. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "theme_items") {
  805. break; // End of <theme_items>.
  806. }
  807. }
  808. } else if (name2 == "constants") {
  809. while (parser->read() == OK) {
  810. if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
  811. String name3 = parser->get_node_name();
  812. if (name3 == "constant") {
  813. ConstantDoc constant2;
  814. ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
  815. constant2.name = parser->get_attribute_value("name");
  816. ERR_FAIL_COND_V(!parser->has_attribute("value"), ERR_FILE_CORRUPT);
  817. constant2.value = parser->get_attribute_value("value");
  818. if (parser->has_attribute("enum")) {
  819. constant2.enumeration = parser->get_attribute_value("enum");
  820. }
  821. if (!parser->is_empty()) {
  822. parser->read();
  823. if (parser->get_node_type() == XMLParser::NODE_TEXT) {
  824. constant2.description = parser->get_node_data();
  825. }
  826. }
  827. c.constants.push_back(constant2);
  828. } else {
  829. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
  830. }
  831. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "constants") {
  832. break; // End of <constants>.
  833. }
  834. }
  835. } else {
  836. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name2 + ".");
  837. }
  838. } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "class") {
  839. break; // End of <class>.
  840. }
  841. }
  842. }
  843. return OK;
  844. }
  845. static void _write_string(FileAccess *f, int p_tablevel, const String &p_string) {
  846. if (p_string == "") {
  847. return;
  848. }
  849. String tab;
  850. for (int i = 0; i < p_tablevel; i++) {
  851. tab += "\t";
  852. }
  853. f->store_string(tab + p_string + "\n");
  854. }
  855. Error DocData::save_classes(const String &p_default_path, const Map<String, String> &p_class_path) {
  856. for (Map<String, ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
  857. ClassDoc &c = E->get();
  858. String save_path;
  859. if (p_class_path.has(c.name)) {
  860. save_path = p_class_path[c.name];
  861. } else {
  862. save_path = p_default_path;
  863. }
  864. Error err;
  865. String save_file = save_path.plus_file(c.name + ".xml");
  866. FileAccessRef f = FileAccess::open(save_file, FileAccess::WRITE, &err);
  867. ERR_CONTINUE_MSG(err != OK, "Can't write doc file: " + save_file + ".");
  868. _write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
  869. String header = "<class name=\"" + c.name + "\"";
  870. if (c.inherits != "") {
  871. header += " inherits=\"" + c.inherits + "\"";
  872. }
  873. header += String(" version=\"") + VERSION_BRANCH + "\"";
  874. header += ">";
  875. _write_string(f, 0, header);
  876. _write_string(f, 1, "<brief_description>");
  877. _write_string(f, 2, c.brief_description.strip_edges().xml_escape());
  878. _write_string(f, 1, "</brief_description>");
  879. _write_string(f, 1, "<description>");
  880. _write_string(f, 2, c.description.strip_edges().xml_escape());
  881. _write_string(f, 1, "</description>");
  882. _write_string(f, 1, "<tutorials>");
  883. for (int i = 0; i < c.tutorials.size(); i++) {
  884. TutorialDoc tutorial = c.tutorials.get(i);
  885. String title_attribute = (!tutorial.title.empty()) ? " title=\"" + tutorial.title.xml_escape() + "\"" : "";
  886. _write_string(f, 2, "<link" + title_attribute + ">" + tutorial.link.xml_escape() + "</link>");
  887. }
  888. _write_string(f, 1, "</tutorials>");
  889. _write_string(f, 1, "<methods>");
  890. c.methods.sort();
  891. for (int i = 0; i < c.methods.size(); i++) {
  892. const MethodDoc &m = c.methods[i];
  893. String qualifiers;
  894. if (m.qualifiers != "") {
  895. qualifiers += " qualifiers=\"" + m.qualifiers.xml_escape() + "\"";
  896. }
  897. _write_string(f, 2, "<method name=\"" + m.name + "\"" + qualifiers + ">");
  898. if (m.return_type != "") {
  899. String enum_text;
  900. if (m.return_enum != String()) {
  901. enum_text = " enum=\"" + m.return_enum + "\"";
  902. }
  903. _write_string(f, 3, "<return type=\"" + m.return_type + "\"" + enum_text + " />");
  904. }
  905. for (int j = 0; j < m.arguments.size(); j++) {
  906. const ArgumentDoc &a = m.arguments[j];
  907. String enum_text;
  908. if (a.enumeration != String()) {
  909. enum_text = " enum=\"" + a.enumeration + "\"";
  910. }
  911. if (a.default_value != "") {
  912. _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " default=\"" + a.default_value.xml_escape(true) + "\" />");
  913. } else {
  914. _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " />");
  915. }
  916. }
  917. _write_string(f, 3, "<description>");
  918. _write_string(f, 4, m.description.strip_edges().xml_escape());
  919. _write_string(f, 3, "</description>");
  920. _write_string(f, 2, "</method>");
  921. }
  922. _write_string(f, 1, "</methods>");
  923. if (c.properties.size()) {
  924. _write_string(f, 1, "<members>");
  925. c.properties.sort();
  926. for (int i = 0; i < c.properties.size(); i++) {
  927. String additional_attributes;
  928. if (c.properties[i].enumeration != String()) {
  929. additional_attributes += " enum=\"" + c.properties[i].enumeration + "\"";
  930. }
  931. if (c.properties[i].default_value != String()) {
  932. additional_attributes += " default=\"" + c.properties[i].default_value.xml_escape(true) + "\"";
  933. }
  934. const PropertyDoc &p = c.properties[i];
  935. if (c.properties[i].overridden) {
  936. _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\" override=\"true\"" + additional_attributes + " />");
  937. } else {
  938. _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\"" + additional_attributes + ">");
  939. _write_string(f, 3, p.description.strip_edges().xml_escape());
  940. _write_string(f, 2, "</member>");
  941. }
  942. }
  943. _write_string(f, 1, "</members>");
  944. }
  945. if (c.signals.size()) {
  946. c.signals.sort();
  947. _write_string(f, 1, "<signals>");
  948. for (int i = 0; i < c.signals.size(); i++) {
  949. const MethodDoc &m = c.signals[i];
  950. _write_string(f, 2, "<signal name=\"" + m.name + "\">");
  951. for (int j = 0; j < m.arguments.size(); j++) {
  952. const ArgumentDoc &a = m.arguments[j];
  953. _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\" />");
  954. }
  955. _write_string(f, 3, "<description>");
  956. _write_string(f, 4, m.description.strip_edges().xml_escape());
  957. _write_string(f, 3, "</description>");
  958. _write_string(f, 2, "</signal>");
  959. }
  960. _write_string(f, 1, "</signals>");
  961. }
  962. _write_string(f, 1, "<constants>");
  963. for (int i = 0; i < c.constants.size(); i++) {
  964. const ConstantDoc &k = c.constants[i];
  965. if (k.enumeration != String()) {
  966. _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">");
  967. } else {
  968. _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\">");
  969. }
  970. _write_string(f, 3, k.description.strip_edges().xml_escape());
  971. _write_string(f, 2, "</constant>");
  972. }
  973. _write_string(f, 1, "</constants>");
  974. if (c.theme_properties.size()) {
  975. c.theme_properties.sort();
  976. _write_string(f, 1, "<theme_items>");
  977. for (int i = 0; i < c.theme_properties.size(); i++) {
  978. const ThemeItemDoc &ti = c.theme_properties[i];
  979. if (ti.default_value != "") {
  980. _write_string(f, 2, "<theme_item name=\"" + ti.name + "\" data_type=\"" + ti.data_type + "\" type=\"" + ti.type + "\" default=\"" + ti.default_value.xml_escape(true) + "\">");
  981. } else {
  982. _write_string(f, 2, "<theme_item name=\"" + ti.name + "\" data_type=\"" + ti.data_type + "\" type=\"" + ti.type + "\">");
  983. }
  984. _write_string(f, 3, ti.description.strip_edges().xml_escape());
  985. _write_string(f, 2, "</theme_item>");
  986. }
  987. _write_string(f, 1, "</theme_items>");
  988. }
  989. _write_string(f, 0, "</class>");
  990. }
  991. return OK;
  992. }
  993. Error DocData::load_compressed(const uint8_t *p_data, int p_compressed_size, int p_uncompressed_size) {
  994. Vector<uint8_t> data;
  995. data.resize(p_uncompressed_size);
  996. Compression::decompress(data.ptrw(), p_uncompressed_size, p_data, p_compressed_size, Compression::MODE_DEFLATE);
  997. class_list.clear();
  998. Ref<XMLParser> parser = memnew(XMLParser);
  999. Error err = parser->open_buffer(data);
  1000. if (err) {
  1001. return err;
  1002. }
  1003. _load(parser);
  1004. return OK;
  1005. }