doc_data.cpp 38 KB

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