Debian Codegraph @

editor/doc/doc_tools.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* doc_tools.cpp */
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
31 #include "doc_tools.h"
32
33 #include "core/config/engine.h"
34 #include "core/config/project_settings.h"
35 #include "core/core_constants.h"
36 #include "core/doc_data.h"
37 #include "core/io/compression.h"
38 #include "core/io/dir_access.h"
39 #include "core/io/resource_importer.h"
40 #include "core/object/script_language.h"
41 #include "core/string/translation_server.h"
42 #include "editor/export/editor_export_platform.h"
43 #include "editor/settings/editor_settings.h"
44 #include "scene/resources/theme.h"
45 #include "scene/theme/theme_db.h"
46
47 // Used for a hack preserving Mono properties on non-Mono builds.
48 #include "modules/modules_enabled.gen.h" // For mono.
49
50 static String _get_indent(const String &p_text) {
51 String indent;
52 bool has_text = false;
53 int line_start = 0;
54
55 for (int i = 0; i < p_text.length(); i++) {
56 const char32_t c = p_text[i];
57 if (c == '\n') {
58 line_start = i + 1;
59 } else if (c > 32) {
60 has_text = true;
61 indent = p_text.substr(line_start, i - line_start);
62 break; // Indentation of the first line that has text.
63 }
64 }
65 if (!has_text) {
66 return p_text;
67 }
68 return indent;
69 }
70
71 static String _translate_doc_string(const String &p_text) {
72 const String indent = _get_indent(p_text);
73 const String message = p_text.dedent().strip_edges();
74 const String translated = TranslationServer::get_singleton()->get_doc_domain()->translate(message, StringName());
75 // No need to restore stripped edges because they'll be stripped again later.
76 return translated.indent(indent);
77 }
78
79 // Comparator for constructors, based on `MethodDoc` operator.
80 struct ConstructorCompare {
81 _FORCE_INLINE_ bool operator()(const DocData::MethodDoc &p_lhs, const DocData::MethodDoc &p_rhs) const {
82 // Must be a constructor (i.e. assume named for the class)
83 // We want this arbitrary order for a class "Foo":
84 // - 1. Default constructor: Foo()
85 // - 2. Copy constructor: Foo(Foo)
86 // - 3+. Other constructors Foo(Bar, ...) based on first argument's name
87 if (p_lhs.arguments.is_empty() || p_rhs.arguments.is_empty()) { // 1.
88 return p_lhs.arguments.size() < p_rhs.arguments.size();
89 }
90 if (p_lhs.arguments[0].type == p_lhs.return_type || p_rhs.arguments[0].type == p_lhs.return_type) { // 2.
91 return (p_lhs.arguments[0].type == p_lhs.return_type) || (p_rhs.arguments[0].type != p_lhs.return_type);
92 }
93 return p_lhs.arguments[0] < p_rhs.arguments[0];
94 }
95 };
96
97 // Comparator for operators, compares on name and type.
98 struct OperatorCompare {
99 _FORCE_INLINE_ bool operator()(const DocData::MethodDoc &p_lhs, const DocData::MethodDoc &p_rhs) const {
100 if (p_lhs.name == p_rhs.name) {
101 if (p_lhs.arguments.size() == p_rhs.arguments.size()) {
102 if (p_lhs.arguments.is_empty()) {
103 return false;
104 }
105 return p_lhs.arguments[0].type < p_rhs.arguments[0].type;
106 }
107 return p_lhs.arguments.size() < p_rhs.arguments.size();
108 }
109 return p_lhs.name.naturalcasecmp_to(p_rhs.name) < 0;
110 }
111 };
112
113 // Comparator for methods, compares on names.
114 struct MethodCompare {
115 _FORCE_INLINE_ bool operator()(const DocData::MethodDoc &p_lhs, const DocData::MethodDoc &p_rhs) const {
116 return p_lhs.name.naturalcasecmp_to(p_rhs.name) < 0;
117 }
118 };
119
120 static void merge_constructors(Vector<DocData::MethodDoc> &p_to, const Vector<DocData::MethodDoc> &p_from) {
121 // Get data from `p_from`, to avoid mutation checks.
122 const DocData::MethodDoc *from_ptr = p_from.ptr();
123 int64_t from_size = p_from.size();
124
125 // TODO: Improve constructor merging.
126 for (DocData::MethodDoc &to : p_to) {
127 for (int64_t from_i = 0; from_i < from_size; ++from_i) {
128 const DocData::MethodDoc &from = from_ptr[from_i];
129
130 // Compare argument count first.
131 if (from.arguments.size() != to.arguments.size()) {
132 continue;
133 }
134
135 if (from.name != to.name) {
136 continue;
137 }
138
139 {
140 // Since constructors can repeat, we need to check the type of
141 // the arguments so we make sure they are different.
142 int64_t arg_count = from.arguments.size();
143 Vector<bool> arg_used;
144 arg_used.resize_initialized(arg_count);
145 // Also there is no guarantee that argument ordering will match,
146 // so we have to check one by one so we make sure we have an exact match.
147 for (int64_t arg_i = 0; arg_i < arg_count; ++arg_i) {
148 for (int64_t arg_j = 0; arg_j < arg_count; ++arg_j) {
149 if (from.arguments[arg_i].type == to.arguments[arg_j].type && !arg_used[arg_j]) {
150 arg_used.write[arg_j] = true;
151 break;
152 }
153 }
154 }
155 bool not_the_same = false;
156 for (int64_t arg_i = 0; arg_i < arg_count; ++arg_i) {
157 if (!arg_used[arg_i]) { // At least one of the arguments was different.
158 not_the_same = true;
159 break;
160 }
161 }
162 if (not_the_same) {
163 continue;
164 }
165 }
166
167 to.description = from.description;
168 to.is_deprecated = from.is_deprecated;
169 to.deprecated_message = from.deprecated_message;
170 to.is_experimental = from.is_experimental;
171 to.experimental_message = from.experimental_message;
172 break;
173 }
174 }
175 }
176
177 static void merge_methods(Vector<DocData::MethodDoc> &p_to, const Vector<DocData::MethodDoc> &p_from) {
178 // Get data from `p_to`, to avoid mutation checks. Searching will be done in the sorted `p_to` from the (potentially) unsorted `p_from`.
179 DocData::MethodDoc *to_ptrw = p_to.ptrw();
180 int64_t to_size = p_to.size();
181
182 for (const DocData::MethodDoc &from : p_from) {
183 int64_t found = p_to.span().bisect<MethodCompare>(from, true);
184
185 if (found >= to_size) {
186 continue;
187 }
188
189 DocData::MethodDoc &to = to_ptrw[found];
190
191 // Check found entry on name.
192 if (to.name == from.name) {
193 to.description = from.description;
194 to.is_deprecated = from.is_deprecated;
195 to.deprecated_message = from.deprecated_message;
196 to.is_experimental = from.is_experimental;
197 to.experimental_message = from.experimental_message;
198 to.keywords = from.keywords;
199 }
200 }
201 }
202
203 static void merge_constants(Vector<DocData::ConstantDoc> &p_to, const Vector<DocData::ConstantDoc> &p_from) {
204 // Get data from `p_from`, to avoid mutation checks. Searching will be done in the sorted `p_from` from the unsorted `p_to`.
205 const DocData::ConstantDoc *from_ptr = p_from.ptr();
206 int64_t from_size = p_from.size();
207
208 for (DocData::ConstantDoc &to : p_to) {
209 int64_t found = p_from.span().bisect(to, true);
210
211 if (found >= from_size) {
212 continue;
213 }
214
215 // Check found entry on name.
216 const DocData::ConstantDoc &from = from_ptr[found];
217
218 if (from.name == to.name) {
219 to.description = from.description;
220 to.is_deprecated = from.is_deprecated;
221 to.deprecated_message = from.deprecated_message;
222 to.is_experimental = from.is_experimental;
223 to.experimental_message = from.experimental_message;
224 to.keywords = from.keywords;
225 }
226 }
227 }
228
229 static void merge_properties(Vector<DocData::PropertyDoc> &p_to, const Vector<DocData::PropertyDoc> &p_from) {
230 // Get data from `p_to`, to avoid mutation checks. Searching will be done in the sorted `p_to` from the (potentially) unsorted `p_from`.
231 DocData::PropertyDoc *to_ptrw = p_to.ptrw();
232 int64_t to_size = p_to.size();
233
234 for (const DocData::PropertyDoc &from : p_from) {
235 int64_t found = p_to.span().bisect(from, true);
236
237 if (found >= to_size) {
238 continue;
239 }
240
241 DocData::PropertyDoc &to = to_ptrw[found];
242
243 // Check found entry on name.
244 if (to.name == from.name) {
245 to.description = from.description;
246 to.is_deprecated = from.is_deprecated;
247 to.deprecated_message = from.deprecated_message;
248 to.is_experimental = from.is_experimental;
249 to.experimental_message = from.experimental_message;
250 to.keywords = from.keywords;
251 }
252 }
253 }
254
255 static void merge_theme_properties(Vector<DocData::ThemeItemDoc> &p_to, const Vector<DocData::ThemeItemDoc> &p_from) {
256 // Get data from `p_to`, to avoid mutation checks. Searching will be done in the sorted `p_to` from the (potentially) unsorted `p_from`.
257 DocData::ThemeItemDoc *to_ptrw = p_to.ptrw();
258 int64_t to_size = p_to.size();
259
260 for (const DocData::ThemeItemDoc &from : p_from) {
261 int64_t found = p_to.span().bisect(from, true);
262
263 if (found >= to_size) {
264 continue;
265 }
266
267 DocData::ThemeItemDoc &to = to_ptrw[found];
268
269 // Check found entry on name and data type.
270 if (to.name == from.name && to.data_type == from.data_type) {
271 to.description = from.description;
272 to.is_deprecated = from.is_deprecated;
273 to.deprecated_message = from.deprecated_message;
274 to.is_experimental = from.is_experimental;
275 to.experimental_message = from.experimental_message;
276 to.keywords = from.keywords;
277 }
278 }
279 }
280
281 static void merge_operators(Vector<DocData::MethodDoc> &p_to, const Vector<DocData::MethodDoc> &p_from) {
282 // Get data from `p_to`, to avoid mutation checks. Searching will be done in the sorted `p_to` from the (potentially) unsorted `p_from`.
283 DocData::MethodDoc *to_ptrw = p_to.ptrw();
284 int64_t to_size = p_to.size();
285
286 for (const DocData::MethodDoc &from : p_from) {
287 int64_t found = p_to.span().bisect(from, true);
288
289 if (found >= to_size) {
290 continue;
291 }
292
293 DocData::MethodDoc &to = to_ptrw[found];
294
295 // Check found entry on name and argument.
296 if (to.name == from.name && to.arguments.size() == from.arguments.size() && (to.arguments.is_empty() || to.arguments[0].type == from.arguments[0].type)) {
297 to.description = from.description;
298 to.is_deprecated = from.is_deprecated;
299 to.deprecated_message = from.deprecated_message;
300 to.is_experimental = from.is_experimental;
301 to.experimental_message = from.experimental_message;
302 }
303 }
304 }
305
306 void DocTools::merge_from(const DocTools &p_data) {
307 for (KeyValue<String, DocData::ClassDoc> &E : class_list) {
308 DocData::ClassDoc &c = E.value;
309
310 if (!p_data.class_list.has(c.name)) {
311 continue;
312 }
313
314 const DocData::ClassDoc &cf = p_data.class_list[c.name];
315
316 c.is_deprecated = cf.is_deprecated;
317 c.deprecated_message = cf.deprecated_message;
318 c.is_experimental = cf.is_experimental;
319 c.experimental_message = cf.experimental_message;
320 c.keywords = cf.keywords;
321
322 c.description = cf.description;
323 c.brief_description = cf.brief_description;
324 c.tutorials = cf.tutorials;
325
326 merge_constructors(c.constructors, cf.constructors);
327
328 merge_methods(c.methods, cf.methods);
329
330 merge_methods(c.signals, cf.signals);
331
332 merge_constants(c.constants, cf.constants);
333
334 merge_methods(c.annotations, cf.annotations);
335
336 merge_properties(c.properties, cf.properties);
337
338 merge_theme_properties(c.theme_properties, cf.theme_properties);
339
340 merge_operators(c.operators, cf.operators);
341 }
342 }
343
344 void DocTools::add_doc(const DocData::ClassDoc &p_class_doc) {
345 ERR_FAIL_COND(p_class_doc.name.is_empty());
346 class_list[p_class_doc.name] = p_class_doc;
347 inheriting[p_class_doc.inherits].insert(p_class_doc.name);
348 }
349
350 void DocTools::remove_doc(const String &p_class_name) {
351 ERR_FAIL_COND(p_class_name.is_empty() || !class_list.has(p_class_name));
352 const String &inherits = class_list[p_class_name].inherits;
353 if (inheriting.has(inherits)) {
354 inheriting[inherits].erase(p_class_name);
355 if (inheriting[inherits].is_empty()) {
356 inheriting.erase(inherits);
357 }
358 }
359 class_list.erase(p_class_name);
360 }
361
362 void DocTools::remove_script_doc_by_path(const String &p_path) {
363 for (KeyValue<String, DocData::ClassDoc> &E : class_list) {
364 if (E.value.is_script_doc && E.value.script_path == p_path) {
365 remove_doc(E.key);
366 return;
367 }
368 }
369 }
370
371 bool DocTools::has_doc(const String &p_class_name) {
372 if (p_class_name.is_empty()) {
373 return false;
374 }
375 return class_list.has(p_class_name);
376 }
377
378 static Variant get_documentation_default_value(const StringName &p_class_name, const StringName &p_property_name, bool &r_default_value_valid) {
379 Variant default_value = Variant();
380 r_default_value_valid = false;
381
382 if (ClassDB::can_instantiate(p_class_name) && !ClassDB::is_virtual(p_class_name)) { // Keep this condition in sync with ClassDB::class_get_default_property_value.
383 default_value = ClassDB::class_get_default_property_value(p_class_name, p_property_name, &r_default_value_valid);
384 } else {
385 // Cannot get default value of classes that can't be instantiated.
386
387 // Let's see if the abstract class has an explicitly set default.
388 const HashMap<StringName, Variant> *default_properties = ClassDB::default_values.getptr(p_class_name);
389 if (default_properties) {
390 const Variant *property = default_properties->getptr(p_property_name);
391 if (property) {
392 r_default_value_valid = true;
393 return *property;
394 }
395 }
396
397 List<StringName> inheriting_classes;
398 ClassDB::get_direct_inheriters_from_class(p_class_name, &inheriting_classes);
399 for (const StringName &class_name : inheriting_classes) {
400 if (ClassDB::can_instantiate(class_name)) {
401 default_value = ClassDB::class_get_default_property_value(class_name, p_property_name, &r_default_value_valid);
402 if (r_default_value_valid) {
403 break;
404 }
405 }
406 }
407 }
408
409 return default_value;
410 }
411
412 void DocTools::generate(BitField<GenerateFlags> p_flags) {
413 // This may involve instantiating classes that are only usable from the main thread
414 // (which is in fact the case of the core API).
415 ERR_FAIL_COND(!Thread::is_main_thread());
416
417 // Add ClassDB-exposed classes.
418 {
419 LocalVector<StringName> classes;
420 if (p_flags.has_flag(GENERATE_FLAG_EXTENSION_CLASSES_ONLY)) {
421 ClassDB::get_extensions_class_list(classes);
422 } else {
423 ClassDB::get_class_list(classes);
424 // Move ProjectSettings, so that other classes can register properties there.
425 classes.erase("ProjectSettings");
426 classes.push_back("ProjectSettings");
427 }
428
429 bool skip_setter_getter_methods = true;
430
431 // Populate documentation data for each exposed class.
432 for (uint32_t classes_idx = 0; classes_idx < classes.size(); classes_idx++) {
433 const String &name = classes[classes_idx];
434 if (!ClassDB::is_class_exposed(name)) {
435 print_verbose(vformat("Class '%s' is not exposed, skipping.", name));
436 continue;
437 }
438
439 const String &cname = name;
440 // Property setters and getters do not get exposed as individual methods.
441 HashSet<StringName> setters_getters;
442
443 class_list[cname] = DocData::ClassDoc();
444 DocData::ClassDoc &c = class_list[cname];
445 c.name = cname;
446 c.inherits = ClassDB::get_parent_class(name);
447
448 inheriting[c.inherits].insert(cname);
449
450 List<PropertyInfo> properties;
451 List<PropertyInfo> own_properties;
452
453 // Special cases for editor/project settings, and ResourceImporter classes,
454 // we have to rely on Object's property list to get settings and import options.
455 // Otherwise we just use ClassDB's property list (pure registered properties).
456
457 bool properties_from_instance = true; // To skip `script`, etc.
458 bool import_option = false; // Special case for default value.
459 HashMap<StringName, Variant> import_options_default;
460 if (name == "EditorSettings") {
461 // We don't create the full blown EditorSettings (+ config file) with `create()`,
462 // instead we just make a local instance to get default values.
463 Ref<EditorSettings> edset = memnew(EditorSettings);
464 edset->get_property_list(&properties);
465 own_properties = properties;
466 } else if (name == "ProjectSettings") {
467 ProjectSettings::get_singleton()->get_property_list(&properties);
468 own_properties = properties;
469 } else if (ClassDB::is_parent_class(name, "ResourceImporter") && name != "EditorImportPlugin" && ClassDB::can_instantiate(name)) {
470 import_option = true;
471 ResourceImporter *resimp = Object::cast_to<ResourceImporter>(ClassDB::instantiate(name));
472 List<ResourceImporter::ImportOption> options;
473 resimp->get_import_options("", &options);
474 for (const ResourceImporter::ImportOption &option : options) {
475 const PropertyInfo &prop = option.option;
476 properties.push_back(prop);
477 import_options_default[prop.name] = option.default_value;
478 }
479 own_properties = properties;
480 memdelete(resimp);
481 } else if (name.begins_with("EditorExportPlatform") && ClassDB::can_instantiate(name)) {
482 properties_from_instance = false;
483 Ref<EditorExportPlatform> platform = Object::cast_to<EditorExportPlatform>(ClassDB::instantiate(name));
484 if (platform.is_valid()) {
485 List<EditorExportPlatform::ExportOption> options;
486 platform->get_export_options(&options);
487 for (const EditorExportPlatform::ExportOption &E : options) {
488 properties.push_back(E.option);
489 }
490 own_properties = properties;
491 }
492 } else {
493 properties_from_instance = false;
494 ClassDB::get_property_list(name, &properties);
495 ClassDB::get_property_list(name, &own_properties, true);
496 }
497
498 // Sort is still needed here to handle inherited properties, even though it is done below, do not remove.
499 properties.sort();
500 own_properties.sort();
501
502 List<PropertyInfo>::Element *EO = own_properties.front();
503 for (const PropertyInfo &E : properties) {
504 bool inherited = true;
505 if (EO && EO->get() == E) {
506 inherited = false;
507 EO = EO->next();
508 }
509
510 if (properties_from_instance) {
511 if (E.name == "resource_local_to_scene" || E.name == "resource_name" || E.name == "resource_path" || E.name == "script" || E.name == "resource_scene_unique_id") {
512 // Don't include spurious properties from Object property list.
513 continue;
514 }
515 }
516
517 if (E.usage & PROPERTY_USAGE_GROUP || E.usage & PROPERTY_USAGE_SUBGROUP || E.usage & PROPERTY_USAGE_CATEGORY || E.usage & PROPERTY_USAGE_INTERNAL || (E.type == Variant::NIL && E.usage & PROPERTY_USAGE_ARRAY)) {
518 continue;
519 }
520
521 DocData::PropertyDoc prop;
522 prop.name = E.name;
523 prop.overridden = inherited;
524
525 if (inherited) {
526 String parent = ClassDB::get_parent_class(c.name);
527 while (!ClassDB::has_property(parent, prop.name, true)) {
528 parent = ClassDB::get_parent_class(parent);
529 }
530 prop.overrides = parent;
531 }
532
533 bool default_value_valid = false;
534 Variant default_value;
535
536 if (name == "ProjectSettings") {
537 // Special case for project settings, so that settings are not taken from the current project's settings
538 if (!ProjectSettings::get_singleton()->is_builtin_setting(E.name)) {
539 continue;
540 }
541 if (E.usage & PROPERTY_USAGE_EDITOR) {
542 if (!ProjectSettings::get_singleton()->get_ignore_value_in_docs(E.name)) {
543 default_value = ProjectSettings::get_singleton()->property_get_revert(E.name);
544 default_value_valid = true;
545 }
546 }
547 } else if (name == "EditorSettings") {
548 // Special case for editor settings, to prevent hardware or OS specific settings to affect the result.
549 } else if (import_option) {
550 default_value = import_options_default[E.name];
551 default_value_valid = true;
552 } else {
553 default_value = get_documentation_default_value(name, E.name, default_value_valid);
554 if (inherited) {
555 bool base_default_value_valid = false;
556 Variant base_default_value = get_documentation_default_value(ClassDB::get_parent_class(name), E.name, base_default_value_valid);
557 if (!default_value_valid || !base_default_value_valid || default_value == base_default_value) {
558 continue;
559 }
560 }
561 }
562
563 if (default_value_valid && default_value.get_type() != Variant::OBJECT) {
564 prop.default_value = DocData::get_default_value_string(default_value);
565 }
566
567 StringName setter = ClassDB::get_property_setter(name, E.name);
568 StringName getter = ClassDB::get_property_getter(name, E.name);
569
570 prop.setter = setter;
571 prop.getter = getter;
572
573 bool found_type = false;
574 if (getter != StringName()) {
575 MethodBind *mb = ClassDB::get_method(name, getter);
576 if (mb) {
577 PropertyInfo retinfo = mb->get_return_info();
578
579 found_type = true;
580 if (retinfo.type == Variant::INT && retinfo.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD)) {
581 prop.enumeration = retinfo.class_name;
582 prop.is_bitfield = retinfo.usage & PROPERTY_USAGE_CLASS_IS_BITFIELD;
583 prop.type = "int";
584 } else if (retinfo.class_name != StringName()) {
585 prop.type = retinfo.class_name;
586 } else if (retinfo.type == Variant::ARRAY && retinfo.hint == PROPERTY_HINT_ARRAY_TYPE) {
587 prop.type = retinfo.hint_string + "[]";
588 } else if (retinfo.type == Variant::DICTIONARY && retinfo.hint == PROPERTY_HINT_DICTIONARY_TYPE) {
589 prop.type = "Dictionary[" + retinfo.hint_string.replace(";", ", ") + "]";
590 } else if (retinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
591 prop.type = retinfo.hint_string;
592 } else if (retinfo.type == Variant::NIL && retinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
593 prop.type = "Variant";
594 } else if (retinfo.type == Variant::NIL) {
595 prop.type = "void";
596 } else {
597 prop.type = Variant::get_type_name(retinfo.type);
598 }
599 }
600
601 setters_getters.insert(getter);
602 }
603
604 if (setter != StringName()) {
605 setters_getters.insert(setter);
606 }
607
608 if (!found_type) {
609 if (E.type == Variant::OBJECT && E.hint == PROPERTY_HINT_RESOURCE_TYPE) {
610 prop.type = E.hint_string;
611 } else {
612 prop.type = Variant::get_type_name(E.type);
613 }
614 }
615
616 c.properties.push_back(prop);
617 }
618
619 c.properties.sort();
620
621 List<MethodInfo> method_list;
622 ClassDB::get_method_list(name, &method_list, true);
623
624 for (const MethodInfo &E : method_list) {
625 if (E.name.is_empty() || (E.name[0] == '_' && !(E.flags & METHOD_FLAG_VIRTUAL))) {
626 continue; //hidden, don't count
627 }
628
629 if (skip_setter_getter_methods && setters_getters.has(E.name)) {
630 // Don't skip parametric setters and getters, i.e. method which require
631 // one or more parameters to define what property should be set or retrieved.
632 // E.g. CPUParticles3D::set_param(Parameter param, float value).
633 if (E.arguments.is_empty() /* getter */ || (E.arguments.size() == 1 && E.return_val.type == Variant::NIL /* setter */)) {
634 continue;
635 }
636 }
637
638 DocData::MethodDoc method;
639 DocData::method_doc_from_methodinfo(method, E, "");
640
641 Vector<Error> errs = ClassDB::get_method_error_return_values(name, E.name);
642 if (errs.size()) {
643 if (!errs.has(OK)) {
644 errs.insert(0, OK);
645 }
646 for (int i = 0; i < errs.size(); i++) {
647 if (!method.errors_returned.has(errs[i])) {
648 method.errors_returned.push_back(errs[i]);
649 }
650 }
651 }
652
653 c.methods.push_back(method);
654 }
655
656 c.methods.sort_custom<MethodCompare>();
657
658 List<MethodInfo> signal_list;
659 ClassDB::get_signal_list(name, &signal_list, true);
660
661 if (signal_list.size()) {
662 for (const MethodInfo &mi : signal_list) {
663 if (mi.name.is_empty() || mi.name[0] == '_') {
664 continue; // Hidden, don't count.
665 }
666
667 DocData::MethodDoc signal;
668 signal.name = mi.name;
669 for (const PropertyInfo &arginfo : mi.arguments) {
670 DocData::ArgumentDoc argument;
671 DocData::argument_doc_from_arginfo(argument, arginfo);
672
673 signal.arguments.push_back(argument);
674 }
675
676 c.signals.push_back(signal);
677 }
678
679 c.signals.sort_custom<MethodCompare>();
680 }
681
682 List<String> constant_list;
683 ClassDB::get_integer_constant_list(name, &constant_list, true);
684
685 for (const String &E : constant_list) {
686 DocData::ConstantDoc constant;
687 constant.name = E;
688 constant.value = itos(ClassDB::get_integer_constant(name, E));
689 constant.is_value_valid = true;
690 constant.type = "int";
691 constant.enumeration = ClassDB::get_integer_constant_enum(name, E);
692 constant.is_bitfield = ClassDB::is_enum_bitfield(name, constant.enumeration);
693 c.constants.push_back(constant);
694 }
695
696 // Theme items.
697 {
698 List<ThemeDB::ThemeItemBind> theme_items;
699 ThemeDB::get_singleton()->get_class_items(cname, &theme_items);
700 Ref<Theme> default_theme = ThemeDB::get_singleton()->get_default_theme();
701
702 for (const ThemeDB::ThemeItemBind &theme_item : theme_items) {
703 DocData::ThemeItemDoc tid;
704 tid.name = theme_item.item_name;
705
706 switch (theme_item.data_type) {
707 case Theme::DATA_TYPE_COLOR:
708 tid.type = "Color";
709 tid.data_type = "color";
710 break;
711 case Theme::DATA_TYPE_CONSTANT:
712 tid.type = "int";
713 tid.data_type = "constant";
714 break;
715 case Theme::DATA_TYPE_FONT:
716 tid.type = "Font";
717 tid.data_type = "font";
718 break;
719 case Theme::DATA_TYPE_FONT_SIZE:
720 tid.type = "int";
721 tid.data_type = "font_size";
722 break;
723 case Theme::DATA_TYPE_ICON:
724 tid.type = "Texture2D";
725 tid.data_type = "icon";
726 break;
727 case Theme::DATA_TYPE_STYLEBOX:
728 tid.type = "StyleBox";
729 tid.data_type = "style";
730 break;
731 case Theme::DATA_TYPE_MAX:
732 break; // Can't happen, but silences warning.
733 }
734
735 if (theme_item.data_type == Theme::DATA_TYPE_COLOR || theme_item.data_type == Theme::DATA_TYPE_CONSTANT) {
736 tid.default_value = DocData::get_default_value_string(default_theme->get_theme_item(theme_item.data_type, theme_item.item_name, cname));
737 }
738
739 c.theme_properties.push_back(tid);
740 }
741
742 c.theme_properties.sort();
743 }
744 }
745 }
746
747 if (p_flags.has_flag(GENERATE_FLAG_SKIP_BASIC_TYPES)) {
748 return;
749 }
750
751 // Add a dummy Variant entry.
752 {
753 // This allows us to document the concept of Variant even though
754 // it's not a ClassDB-exposed class.
755 class_list["Variant"] = DocData::ClassDoc();
756 class_list["Variant"].name = "Variant";
757 inheriting[""].insert("Variant");
758 }
759
760 // Add Variant data types.
761 for (int i = 0; i < Variant::VARIANT_MAX; i++) {
762 if (i == Variant::NIL) {
763 continue; // Not exposed outside of 'null', should not be in class list.
764 }
765 if (i == Variant::OBJECT) {
766 continue; // Use the core type instead.
767 }
768
769 String cname = Variant::get_type_name(Variant::Type(i));
770
771 class_list[cname] = DocData::ClassDoc();
772 DocData::ClassDoc &c = class_list[cname];
773 c.name = cname;
774
775 inheriting[""].insert(cname);
776
777 Callable::CallError cerror;
778 Variant v;
779 Variant::construct(Variant::Type(i), v, nullptr, 0, cerror);
780
781 List<MethodInfo> method_list;
782 v.get_method_list(&method_list);
783 Variant::get_constructor_list(Variant::Type(i), &method_list);
784
785 for (int j = 0; j < Variant::OP_AND; j++) { // Showing above 'and' is pretty confusing and there are a lot of variations.
786 for (int k = 0; k < Variant::VARIANT_MAX; k++) {
787 // Prevent generating for comparison with null.
788 if (Variant::Type(k) == Variant::NIL && (Variant::Operator(j) == Variant::OP_EQUAL || Variant::Operator(j) == Variant::OP_NOT_EQUAL)) {
789 continue;
790 }
791
792 Variant::Type rt = Variant::get_operator_return_type(Variant::Operator(j), Variant::Type(i), Variant::Type(k));
793 if (rt != Variant::NIL) { // Has operator.
794 // Skip String % operator as it's registered separately for each Variant arg type,
795 // we'll add it manually below.
796 if ((i == Variant::STRING || i == Variant::STRING_NAME) && Variant::Operator(j) == Variant::OP_MODULE) {
797 continue;
798 }
799 MethodInfo mi;
800 mi.name = "operator " + Variant::get_operator_name(Variant::Operator(j));
801 mi.return_val.type = rt;
802 if (k != Variant::NIL) {
803 PropertyInfo arg;
804 arg.name = "right";
805 arg.type = Variant::Type(k);
806 mi.arguments.push_back(arg);
807 }
808 method_list.push_back(mi);
809 }
810 }
811 }
812
813 if (i == Variant::STRING || i == Variant::STRING_NAME) {
814 // We skipped % operator above, and we register it manually once for Variant arg type here.
815 MethodInfo mi;
816 mi.name = "operator %";
817 mi.return_val.type = Variant::STRING;
818
819 PropertyInfo arg;
820 arg.name = "right";
821 arg.type = Variant::NIL;
822 arg.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
823 mi.arguments.push_back(arg);
824
825 method_list.push_back(mi);
826 }
827
828 if (Variant::is_keyed(Variant::Type(i))) {
829 MethodInfo mi;
830 mi.name = "operator []";
831 mi.return_val.type = Variant::NIL;
832 mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
833
834 PropertyInfo arg;
835 arg.name = "key";
836 arg.type = Variant::NIL;
837 arg.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
838 mi.arguments.push_back(arg);
839
840 method_list.push_back(mi);
841 } else if (Variant::has_indexing(Variant::Type(i))) {
842 MethodInfo mi;
843 mi.name = "operator []";
844 mi.return_val.type = Variant::get_indexed_element_type(Variant::Type(i));
845 mi.return_val.usage = Variant::get_indexed_element_usage(Variant::Type(i));
846 PropertyInfo arg;
847 arg.name = "index";
848 arg.type = Variant::INT;
849 mi.arguments.push_back(arg);
850
851 method_list.push_back(mi);
852 }
853
854 for (const MethodInfo &mi : method_list) {
855 DocData::MethodDoc method;
856
857 method.name = mi.name;
858
859 for (int64_t j = 0; j < mi.arguments.size(); ++j) {
860 const PropertyInfo &arginfo = mi.arguments[j];
861 DocData::ArgumentDoc ad;
862 DocData::argument_doc_from_arginfo(ad, arginfo);
863 ad.name = arginfo.name;
864
865 int darg_idx = mi.default_arguments.size() - mi.arguments.size() + j;
866 if (darg_idx >= 0) {
867 ad.default_value = DocData::get_default_value_string(mi.default_arguments[darg_idx]);
868 }
869
870 method.arguments.push_back(ad);
871 }
872
873 DocData::return_doc_from_retinfo(method, mi.return_val);
874
875 if (mi.flags & METHOD_FLAG_VARARG) {
876 if (!method.qualifiers.is_empty()) {
877 method.qualifiers += " ";
878 }
879 method.qualifiers += "vararg";
880 }
881
882 if (mi.flags & METHOD_FLAG_CONST) {
883 if (!method.qualifiers.is_empty()) {
884 method.qualifiers += " ";
885 }
886 method.qualifiers += "const";
887 }
888
889 if (mi.flags & METHOD_FLAG_STATIC) {
890 if (!method.qualifiers.is_empty()) {
891 method.qualifiers += " ";
892 }
893 method.qualifiers += "static";
894 }
895
896 if (method.name == cname) {
897 c.constructors.push_back(method);
898 } else if (method.name.begins_with("operator")) {
899 c.operators.push_back(method);
900 } else {
901 c.methods.push_back(method);
902 }
903 }
904
905 c.constructors.sort_custom<ConstructorCompare>();
906 c.operators.sort_custom<OperatorCompare>();
907 c.methods.sort_custom<MethodCompare>();
908
909 List<PropertyInfo> properties;
910 v.get_property_list(&properties);
911 for (const PropertyInfo &pi : properties) {
912 DocData::PropertyDoc property;
913 property.name = pi.name;
914 property.type = Variant::get_type_name(pi.type);
915 property.default_value = DocData::get_default_value_string(v.get(pi.name));
916
917 c.properties.push_back(property);
918 }
919
920 c.properties.sort();
921
922 List<StringName> enums;
923 Variant::get_enums_for_type(Variant::Type(i), &enums);
924
925 for (const StringName &E : enums) {
926 List<StringName> enumerations;
927 Variant::get_enumerations_for_enum(Variant::Type(i), E, &enumerations);
928
929 for (const StringName &F : enumerations) {
930 DocData::ConstantDoc constant;
931 constant.name = F;
932 constant.value = itos(Variant::get_enum_value(Variant::Type(i), E, F));
933 constant.is_value_valid = true;
934 constant.type = "int";
935 constant.enumeration = E;
936 c.constants.push_back(constant);
937 }
938 }
939
940 List<StringName> constants;
941 Variant::get_constants_for_type(Variant::Type(i), &constants);
942
943 for (const StringName &E : constants) {
944 DocData::ConstantDoc constant;
945 constant.name = E;
946 Variant value = Variant::get_constant_value(Variant::Type(i), E);
947 constant.value = DocData::get_default_value_string(value);
948 constant.is_value_valid = true;
949 constant.type = Variant::get_type_name(value.get_type());
950 c.constants.push_back(constant);
951 }
952 }
953
954 // Add global API (servers, engine singletons, global constants) and Variant utility functions.
955 {
956 String cname = "@GlobalScope";
957 class_list[cname] = DocData::ClassDoc();
958 DocData::ClassDoc &c = class_list[cname];
959 c.name = cname;
960
961 inheriting[""].insert(cname);
962
963 // Global constants.
964 for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) {
965 DocData::ConstantDoc cd;
966 cd.name = CoreConstants::get_global_constant_name(i);
967 cd.type = "int";
968 cd.enumeration = CoreConstants::get_global_constant_enum(i);
969 cd.is_bitfield = CoreConstants::is_global_constant_bitfield(i);
970 if (!CoreConstants::get_ignore_value_in_docs(i)) {
971 cd.value = itos(CoreConstants::get_global_constant_value(i));
972 cd.is_value_valid = true;
973 } else {
974 cd.is_value_valid = false;
975 }
976 c.constants.push_back(cd);
977 }
978
979 // Servers/engine singletons.
980 List<Engine::Singleton> singletons;
981 Engine::get_singleton()->get_singletons(&singletons);
982
983 // FIXME: this is kind of hackish...
984 for (const Engine::Singleton &s : singletons) {
985 DocData::PropertyDoc pd;
986 if (!s.ptr) {
987 continue;
988 }
989 pd.name = s.name;
990 pd.type = s.ptr->get_class();
991 while (String(ClassDB::get_parent_class(pd.type)) != "Object") {
992 pd.type = ClassDB::get_parent_class(pd.type);
993 }
994 c.properties.push_back(pd);
995 }
996
997 c.properties.sort();
998
999 // Variant utility functions.
1000 List<StringName> utility_functions;
1001 Variant::get_utility_function_list(&utility_functions);
1002 for (const StringName &E : utility_functions) {
1003 DocData::MethodDoc md;
1004 md.name = E;
1005 // Utility function's return type.
1006 if (Variant::has_utility_function_return_value(E)) {
1007 PropertyInfo pi;
1008 pi.type = Variant::get_utility_function_return_type(E);
1009 if (pi.type == Variant::NIL) {
1010 pi.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
1011 }
1012 DocData::ArgumentDoc ad;
1013 DocData::argument_doc_from_arginfo(ad, pi);
1014 md.return_type = ad.type;
1015 } else {
1016 md.return_type = "void";
1017 }
1018
1019 // Utility function's arguments.
1020 if (Variant::is_utility_function_vararg(E)) {
1021 md.qualifiers = "vararg";
1022 } else {
1023 for (int i = 0; i < Variant::get_utility_function_argument_count(E); i++) {
1024 PropertyInfo pi;
1025 pi.type = Variant::get_utility_function_argument_type(E, i);
1026 pi.name = Variant::get_utility_function_argument_name(E, i);
1027 if (pi.type == Variant::NIL) {
1028 pi.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
1029 }
1030 DocData::ArgumentDoc ad;
1031 DocData::argument_doc_from_arginfo(ad, pi);
1032 md.arguments.push_back(ad);
1033 }
1034 }
1035
1036 c.methods.push_back(md);
1037 }
1038
1039 c.methods.sort_custom<MethodCompare>();
1040 }
1041
1042 // Add scripting language built-ins.
1043 {
1044 // We only add a doc entry for languages which actually define any built-in
1045 // methods, constants, or annotations.
1046 for (int i = 0; i < ScriptServer::get_language_count(); i++) {
1047 ScriptLanguage *lang = ScriptServer::get_language(i);
1048 String cname = "@" + lang->get_name();
1049 DocData::ClassDoc c;
1050 c.name = cname;
1051
1052 inheriting[""].insert(cname);
1053
1054 // Get functions.
1055 List<MethodInfo> minfo;
1056 lang->get_public_functions(&minfo);
1057
1058 for (const MethodInfo &mi : minfo) {
1059 DocData::MethodDoc md;
1060 md.name = mi.name;
1061
1062 if (mi.flags & METHOD_FLAG_VARARG) {
1063 if (!md.qualifiers.is_empty()) {
1064 md.qualifiers += " ";
1065 }
1066 md.qualifiers += "vararg";
1067 }
1068
1069 DocData::return_doc_from_retinfo(md, mi.return_val);
1070
1071 for (int64_t j = 0; j < mi.arguments.size(); ++j) {
1072 DocData::ArgumentDoc ad;
1073 DocData::argument_doc_from_arginfo(ad, mi.arguments[j]);
1074
1075 int darg_idx = j - (mi.arguments.size() - mi.default_arguments.size());
1076 if (darg_idx >= 0) {
1077 ad.default_value = DocData::get_default_value_string(mi.default_arguments[darg_idx]);
1078 }
1079
1080 md.arguments.push_back(ad);
1081 }
1082
1083 c.methods.push_back(md);
1084 }
1085
1086 // Get constants.
1087 List<Pair<String, Variant>> cinfo;
1088 lang->get_public_constants(&cinfo);
1089
1090 for (const Pair<String, Variant> &E : cinfo) {
1091 DocData::ConstantDoc cd;
1092 cd.name = E.first;
1093 cd.value = E.second;
1094 cd.is_value_valid = true;
1095 cd.type = Variant::get_type_name(E.second.get_type());
1096 c.constants.push_back(cd);
1097 }
1098
1099 // Get annotations.
1100 List<MethodInfo> ainfo;
1101 lang->get_public_annotations(&ainfo);
1102
1103 for (const MethodInfo &ai : ainfo) {
1104 DocData::MethodDoc atd;
1105 atd.name = ai.name;
1106
1107 if (ai.flags & METHOD_FLAG_VARARG) {
1108 if (!atd.qualifiers.is_empty()) {
1109 atd.qualifiers += " ";
1110 }
1111 atd.qualifiers += "vararg";
1112 }
1113
1114 DocData::return_doc_from_retinfo(atd, ai.return_val);
1115
1116 for (int64_t j = 0; j < ai.arguments.size(); ++j) {
1117 DocData::ArgumentDoc ad;
1118 DocData::argument_doc_from_arginfo(ad, ai.arguments[j]);
1119
1120 int64_t darg_idx = j - (ai.arguments.size() - ai.default_arguments.size());
1121 if (darg_idx >= 0) {
1122 ad.default_value = DocData::get_default_value_string(ai.default_arguments[darg_idx]);
1123 }
1124
1125 atd.arguments.push_back(ad);
1126 }
1127
1128 c.annotations.push_back(atd);
1129 }
1130
1131 // Skip adding the lang if it doesn't expose anything (e.g. C#).
1132 if (c.methods.is_empty() && c.constants.is_empty() && c.annotations.is_empty()) {
1133 continue;
1134 }
1135
1136 c.methods.sort_custom<MethodCompare>();
1137 c.annotations.sort_custom<MethodCompare>();
1138
1139 class_list[cname] = c;
1140 }
1141 }
1142 }
1143
1144 static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> &methods) {
1145 String section = parser->get_node_name();
1146 String element = section.substr(0, section.length() - 1);
1147
1148 while (parser->read() == OK) {
1149 if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
1150 if (parser->get_node_name() == element) {
1151 DocData::MethodDoc method;
1152 ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
1153 method.name = parser->get_named_attribute_value("name");
1154 if (parser->has_attribute("qualifiers")) {
1155 method.qualifiers = parser->get_named_attribute_value("qualifiers");
1156 }
1157 #ifndef DISABLE_DEPRECATED
1158 if (parser->has_attribute("is_deprecated")) {
1159 method.is_deprecated = parser->get_named_attribute_value("is_deprecated").to_lower() == "true";
1160 }
1161 if (parser->has_attribute("is_experimental")) {
1162 method.is_experimental = parser->get_named_attribute_value("is_experimental").to_lower() == "true";
1163 }
1164 #endif
1165 if (parser->has_attribute("deprecated")) {
1166 method.is_deprecated = true;
1167 method.deprecated_message = parser->get_named_attribute_value("deprecated");
1168 }
1169 if (parser->has_attribute("experimental")) {
1170 method.is_experimental = true;
1171 method.experimental_message = parser->get_named_attribute_value("experimental");
1172 }
1173 if (parser->has_attribute("keywords")) {
1174 method.keywords = parser->get_named_attribute_value("keywords");
1175 }
1176
1177 while (parser->read() == OK) {
1178 if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
1179 String name = parser->get_node_name();
1180 if (name == "return") {
1181 ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
1182 method.return_type = parser->get_named_attribute_value("type");
1183 if (parser->has_attribute("enum")) {
1184 method.return_enum = parser->get_named_attribute_value("enum");
1185 if (parser->has_attribute("is_bitfield")) {
1186 method.return_is_bitfield = parser->get_named_attribute_value("is_bitfield").to_lower() == "true";
1187 }
1188 }
1189 } else if (name == "returns_error") {
1190 ERR_FAIL_COND_V(!parser->has_attribute("number"), ERR_FILE_CORRUPT);
1191 method.errors_returned.push_back(parser->get_named_attribute_value("number").to_int());
1192 } else if (name == "param") {
1193 DocData::ArgumentDoc argument;
1194 ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
1195 argument.name = parser->get_named_attribute_value("name");
1196 ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
1197 argument.type = parser->get_named_attribute_value("type");
1198 if (parser->has_attribute("enum")) {
1199 argument.enumeration = parser->get_named_attribute_value("enum");
1200 if (parser->has_attribute("is_bitfield")) {
1201 argument.is_bitfield = parser->get_named_attribute_value("is_bitfield").to_lower() == "true";
1202 }
1203 }
1204
1205 method.arguments.push_back(argument);
1206
1207 } else if (name == "description") {
1208 parser->read();
1209 if (parser->get_node_type() == XMLParser::NODE_TEXT) {
1210 method.description = parser->get_node_data();
1211 }
1212 }
1213
1214 } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == element) {
1215 break;
1216 }
1217 }
1218
1219 methods.push_back(method);
1220
1221 } else {
1222 ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + parser->get_node_name() + ", expected " + element + ".");
1223 }
1224
1225 } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == section) {
1226 break;
1227 }
1228 }
1229
1230 return OK;
1231 }
1232
1233 Error DocTools::load_classes(const String &p_dir) {
1234 Error err;
1235 Ref<DirAccess> da = DirAccess::open(p_dir, &err);
1236 if (da.is_null()) {
1237 return err;
1238 }
1239
1240 da->list_dir_begin();
1241 String path;
1242 path = da->get_next();
1243 while (!path.is_empty()) {
1244 if (!da->current_is_dir() && path.ends_with("xml")) {
1245 Ref<XMLParser> parser = memnew(XMLParser);
1246 Error err2 = parser->open(p_dir.path_join(path));
1247 if (err2) {
1248 return err2;
1249 }
1250
1251 _load(parser);
1252 }
1253 path = da->get_next();
1254 }
1255
1256 da->list_dir_end();
1257
1258 return OK;
1259 }
1260
1261 Error DocTools::erase_classes(const String &p_dir) {
1262 Error err;
1263 Ref<DirAccess> da = DirAccess::open(p_dir, &err);
1264 if (da.is_null()) {
1265 return err;
1266 }
1267
1268 List<String> to_erase;
1269
1270 da->list_dir_begin();
1271 String path;
1272 path = da->get_next();
1273 while (!path.is_empty()) {
1274 if (!da->current_is_dir() && path.ends_with("xml")) {
1275 to_erase.push_back(path);
1276 }
1277 path = da->get_next();
1278 }
1279 da->list_dir_end();
1280
1281 while (to_erase.size()) {
1282 da->remove(to_erase.front()->get());
1283 to_erase.pop_front();
1284 }
1285
1286 return OK;
1287 }
1288
1289 Error DocTools::_load(Ref<XMLParser> parser) {
1290 Error err = OK;
1291
1292 while ((err = parser->read()) == OK) {
1293 if (parser->get_node_type() == XMLParser::NODE_ELEMENT && parser->get_node_name() == "?xml") {
1294 parser->skip_section();
1295 }
1296
1297 if (parser->get_node_type() != XMLParser::NODE_ELEMENT) {
1298 continue; //no idea what this may be, but skipping anyway
1299 }
1300
1301 ERR_FAIL_COND_V(parser->get_node_name() != "class", ERR_FILE_CORRUPT);
1302
1303 ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
1304 String name = parser->get_named_attribute_value("name");
1305 class_list[name] = DocData::ClassDoc();
1306 DocData::ClassDoc &c = class_list[name];
1307
1308 c.name = name;
1309 if (parser->has_attribute("inherits")) {
1310 c.inherits = parser->get_named_attribute_value("inherits");
1311 }
1312
1313 inheriting[c.inherits].insert(name);
1314
1315 #ifndef DISABLE_DEPRECATED
1316 if (parser->has_attribute("is_deprecated")) {
1317 c.is_deprecated = parser->get_named_attribute_value("is_deprecated").to_lower() == "true";
1318 }
1319 if (parser->has_attribute("is_experimental")) {
1320 c.is_experimental = parser->get_named_attribute_value("is_experimental").to_lower() == "true";
1321 }
1322 #endif
1323 if (parser->has_attribute("deprecated")) {
1324 c.is_deprecated = true;
1325 c.deprecated_message = parser->get_named_attribute_value("deprecated");
1326 }
1327 if (parser->has_attribute("experimental")) {
1328 c.is_experimental = true;
1329 c.experimental_message = parser->get_named_attribute_value("experimental");
1330 }
1331
1332 if (parser->has_attribute("keywords")) {
1333 c.keywords = parser->get_named_attribute_value("keywords");
1334 }
1335
1336 while (parser->read() == OK) {
1337 if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
1338 String name2 = parser->get_node_name();
1339
1340 if (name2 == "brief_description") {
1341 parser->read();
1342 if (parser->get_node_type() == XMLParser::NODE_TEXT) {
1343 c.brief_description = parser->get_node_data();
1344 }
1345
1346 } else if (name2 == "description") {
1347 parser->read();
1348 if (parser->get_node_type() == XMLParser::NODE_TEXT) {
1349 c.description = parser->get_node_data();
1350 }
1351 } else if (name2 == "tutorials") {
1352 while (parser->read() == OK) {
1353 if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
1354 String name3 = parser->get_node_name();
1355
1356 if (name3 == "link") {
1357 DocData::TutorialDoc tutorial;
1358 if (parser->has_attribute("title")) {
1359 tutorial.title = parser->get_named_attribute_value("title");
1360 }
1361 parser->read();
1362 if (parser->get_node_type() == XMLParser::NODE_TEXT) {
1363 tutorial.link = parser->get_node_data().strip_edges();
1364 c.tutorials.push_back(tutorial);
1365 }
1366 } else {
1367 ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
1368 }
1369 } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "tutorials") {
1370 break; // End of <tutorials>.
1371 }
1372 }
1373 } else if (name2 == "constructors") {
1374 Error err2 = _parse_methods(parser, c.constructors);
1375 ERR_FAIL_COND_V(err2, err2);
1376 } else if (name2 == "methods") {
1377 Error err2 = _parse_methods(parser, c.methods);
1378 ERR_FAIL_COND_V(err2, err2);
1379 } else if (name2 == "operators") {
1380 Error err2 = _parse_methods(parser, c.operators);
1381 ERR_FAIL_COND_V(err2, err2);
1382 } else if (name2 == "signals") {
1383 Error err2 = _parse_methods(parser, c.signals);
1384 ERR_FAIL_COND_V(err2, err2);
1385 } else if (name2 == "annotations") {
1386 Error err2 = _parse_methods(parser, c.annotations);
1387 ERR_FAIL_COND_V(err2, err2);
1388 } else if (name2 == "members") {
1389 while (parser->read() == OK) {
1390 if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
1391 String name3 = parser->get_node_name();
1392
1393 if (name3 == "member") {
1394 DocData::PropertyDoc prop2;
1395
1396 ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
1397 prop2.name = parser->get_named_attribute_value("name");
1398 ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
1399 prop2.type = parser->get_named_attribute_value("type");
1400 if (parser->has_attribute("setter")) {
1401 prop2.setter = parser->get_named_attribute_value("setter");
1402 }
1403 if (parser->has_attribute("getter")) {
1404 prop2.getter = parser->get_named_attribute_value("getter");
1405 }
1406 if (parser->has_attribute("enum")) {
1407 prop2.enumeration = parser->get_named_attribute_value("enum");
1408 if (parser->has_attribute("is_bitfield")) {
1409 prop2.is_bitfield = parser->get_named_attribute_value("is_bitfield").to_lower() == "true";
1410 }
1411 }
1412 #ifndef DISABLE_DEPRECATED
1413 if (parser->has_attribute("is_deprecated")) {
1414 prop2.is_deprecated = parser->get_named_attribute_value("is_deprecated").to_lower() == "true";
1415 }
1416 if (parser->has_attribute("is_experimental")) {
1417 prop2.is_experimental = parser->get_named_attribute_value("is_experimental").to_lower() == "true";
1418 }
1419 #endif
1420 if (parser->has_attribute("deprecated")) {
1421 prop2.is_deprecated = true;
1422 prop2.deprecated_message = parser->get_named_attribute_value("deprecated");
1423 }
1424 if (parser->has_attribute("experimental")) {
1425 prop2.is_experimental = true;
1426 prop2.experimental_message = parser->get_named_attribute_value("experimental");
1427 }
1428 if (parser->has_attribute("keywords")) {
1429 prop2.keywords = parser->get_named_attribute_value("keywords");
1430 }
1431 if (!parser->is_empty()) {
1432 parser->read();
1433 if (parser->get_node_type() == XMLParser::NODE_TEXT) {
1434 prop2.description = parser->get_node_data();
1435 }
1436 }
1437 c.properties.push_back(prop2);
1438 } else {
1439 ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
1440 }
1441
1442 } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "members") {
1443 break; // End of <members>.
1444 }
1445 }
1446
1447 } else if (name2 == "theme_items") {
1448 while (parser->read() == OK) {
1449 if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
1450 String name3 = parser->get_node_name();
1451
1452 if (name3 == "theme_item") {
1453 DocData::ThemeItemDoc prop2;
1454
1455 ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
1456 prop2.name = parser->get_named_attribute_value("name");
1457 ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
1458 prop2.type = parser->get_named_attribute_value("type");
1459 ERR_FAIL_COND_V(!parser->has_attribute("data_type"), ERR_FILE_CORRUPT);
1460 prop2.data_type = parser->get_named_attribute_value("data_type");
1461 if (parser->has_attribute("deprecated")) {
1462 prop2.is_deprecated = true;
1463 prop2.deprecated_message = parser->get_named_attribute_value("deprecated");
1464 }
1465 if (parser->has_attribute("experimental")) {
1466 prop2.is_experimental = true;
1467 prop2.experimental_message = parser->get_named_attribute_value("experimental");
1468 }
1469 if (parser->has_attribute("keywords")) {
1470 prop2.keywords = parser->get_named_attribute_value("keywords");
1471 }
1472 if (!parser->is_empty()) {
1473 parser->read();
1474 if (parser->get_node_type() == XMLParser::NODE_TEXT) {
1475 prop2.description = parser->get_node_data();
1476 }
1477 }
1478 c.theme_properties.push_back(prop2);
1479 } else {
1480 ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
1481 }
1482
1483 } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "theme_items") {
1484 break; // End of <theme_items>.
1485 }
1486 }
1487
1488 } else if (name2 == "constants") {
1489 while (parser->read() == OK) {
1490 if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
1491 String name3 = parser->get_node_name();
1492
1493 if (name3 == "constant") {
1494 DocData::ConstantDoc constant2;
1495 ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
1496 constant2.name = parser->get_named_attribute_value("name");
1497 ERR_FAIL_COND_V(!parser->has_attribute("value"), ERR_FILE_CORRUPT);
1498 constant2.value = parser->get_named_attribute_value("value");
1499 constant2.is_value_valid = true;
1500 if (parser->has_attribute("enum")) {
1501 constant2.enumeration = parser->get_named_attribute_value("enum");
1502 if (parser->has_attribute("is_bitfield")) {
1503 constant2.is_bitfield = parser->get_named_attribute_value("is_bitfield").to_lower() == "true";
1504 }
1505 }
1506 #ifndef DISABLE_DEPRECATED
1507 if (parser->has_attribute("is_deprecated")) {
1508 constant2.is_deprecated = parser->get_named_attribute_value("is_deprecated").to_lower() == "true";
1509 }
1510 if (parser->has_attribute("is_experimental")) {
1511 constant2.is_experimental = parser->get_named_attribute_value("is_experimental").to_lower() == "true";
1512 }
1513 #endif
1514 if (parser->has_attribute("deprecated")) {
1515 constant2.is_deprecated = true;
1516 constant2.deprecated_message = parser->get_named_attribute_value("deprecated");
1517 }
1518 if (parser->has_attribute("experimental")) {
1519 constant2.is_experimental = true;
1520 constant2.experimental_message = parser->get_named_attribute_value("experimental");
1521 }
1522 if (parser->has_attribute("keywords")) {
1523 constant2.keywords = parser->get_named_attribute_value("keywords");
1524 }
1525 if (!parser->is_empty()) {
1526 parser->read();
1527 if (parser->get_node_type() == XMLParser::NODE_TEXT) {
1528 constant2.description = parser->get_node_data();
1529 }
1530 }
1531 c.constants.push_back(constant2);
1532 } else {
1533 ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
1534 }
1535
1536 } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "constants") {
1537 break; // End of <constants>.
1538 }
1539 }
1540
1541 } else {
1542 ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name2 + ".");
1543 }
1544
1545 } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "class") {
1546 break; // End of <class>.
1547 }
1548 }
1549
1550 // Sort loaded constants for merging.
1551 c.constants.sort();
1552 }
1553
1554 return OK;
1555 }
1556
1557 static void _write_string(Ref<FileAccess> f, int p_tablevel, const String &p_string) {
1558 if (p_string.is_empty()) {
1559 return;
1560 }
1561 String tab = String("\t").repeat(p_tablevel);
1562 f->store_string(tab + p_string + "\n");
1563 }
1564
1565 static void _write_method_doc(Ref<FileAccess> f, const String &p_name, Vector<DocData::MethodDoc> &p_method_docs) {
1566 if (!p_method_docs.is_empty()) {
1567 _write_string(f, 1, "<" + p_name + "s>");
1568 for (int i = 0; i < p_method_docs.size(); i++) {
1569 const DocData::MethodDoc &m = p_method_docs[i];
1570
1571 String additional_attributes;
1572 if (!m.qualifiers.is_empty()) {
1573 additional_attributes += " qualifiers=\"" + m.qualifiers.xml_escape(true) + "\"";
1574 }
1575 if (m.is_deprecated) {
1576 additional_attributes += " deprecated=\"" + m.deprecated_message.xml_escape(true) + "\"";
1577 }
1578 if (m.is_experimental) {
1579 additional_attributes += " experimental=\"" + m.experimental_message.xml_escape(true) + "\"";
1580 }
1581 if (!m.keywords.is_empty()) {
1582 additional_attributes += String(" keywords=\"") + m.keywords.xml_escape(true) + "\"";
1583 }
1584
1585 _write_string(f, 2, "<" + p_name + " name=\"" + m.name.xml_escape(true) + "\"" + additional_attributes + ">");
1586
1587 if (!m.return_type.is_empty()) {
1588 String enum_text;
1589 if (!m.return_enum.is_empty()) {
1590 enum_text = " enum=\"" + m.return_enum.xml_escape(true) + "\"";
1591 if (m.return_is_bitfield) {
1592 enum_text += " is_bitfield=\"true\"";
1593 }
1594 }
1595 _write_string(f, 3, "<return type=\"" + m.return_type.xml_escape(true) + "\"" + enum_text + " />");
1596 }
1597 if (m.errors_returned.size() > 0) {
1598 for (int j = 0; j < m.errors_returned.size(); j++) {
1599 _write_string(f, 3, "<returns_error number=\"" + itos(m.errors_returned[j]) + "\"/>");
1600 }
1601 }
1602
1603 for (int j = 0; j < m.arguments.size(); j++) {
1604 const DocData::ArgumentDoc &a = m.arguments[j];
1605
1606 String enum_text;
1607 if (!a.enumeration.is_empty()) {
1608 enum_text = " enum=\"" + a.enumeration.xml_escape(true) + "\"";
1609 if (a.is_bitfield) {
1610 enum_text += " is_bitfield=\"true\"";
1611 }
1612 }
1613
1614 if (!a.default_value.is_empty()) {
1615 _write_string(f, 3, "<param index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape(true) + "\" type=\"" + a.type.xml_escape(true) + "\"" + enum_text + " default=\"" + a.default_value.xml_escape(true) + "\" />");
1616 } else {
1617 _write_string(f, 3, "<param index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape(true) + "\" type=\"" + a.type.xml_escape(true) + "\"" + enum_text + " />");
1618 }
1619 }
1620
1621 _write_string(f, 3, "<description>");
1622 _write_string(f, 4, _translate_doc_string(m.description).strip_edges().xml_escape());
1623 _write_string(f, 3, "</description>");
1624
1625 _write_string(f, 2, "</" + p_name + ">");
1626 }
1627
1628 _write_string(f, 1, "</" + p_name + "s>");
1629 }
1630 }
1631
1632 Error DocTools::save_classes(const String &p_default_path, const HashMap<String, String> &p_class_path, bool p_use_relative_schema) {
1633 for (KeyValue<String, DocData::ClassDoc> &E : class_list) {
1634 DocData::ClassDoc &c = E.value;
1635
1636 String save_path;
1637 if (p_class_path.has(c.name)) {
1638 save_path = p_class_path[c.name];
1639 } else {
1640 save_path = p_default_path;
1641 }
1642
1643 Error err;
1644 String save_file = save_path.path_join(c.name.remove_char('\"').replace("/", "--") + ".xml");
1645 Ref<FileAccess> f = FileAccess::open(save_file, FileAccess::WRITE, &err);
1646
1647 ERR_CONTINUE_MSG(err != OK, "Can't write doc file: " + save_file + ".");
1648
1649 _write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
1650
1651 String header = "<class name=\"" + c.name.xml_escape(true) + "\"";
1652 if (!c.inherits.is_empty()) {
1653 header += " inherits=\"" + c.inherits.xml_escape(true) + "\"";
1654 if (c.is_deprecated) {
1655 header += " deprecated=\"" + c.deprecated_message.xml_escape(true) + "\"";
1656 }
1657 if (c.is_experimental) {
1658 header += " experimental=\"" + c.experimental_message.xml_escape(true) + "\"";
1659 }
1660 }
1661 if (!c.keywords.is_empty()) {
1662 header += String(" keywords=\"") + c.keywords.xml_escape(true) + "\"";
1663 }
1664 // Reference the XML schema so editors can provide error checking.
1665 String schema_path;
1666 if (p_use_relative_schema) {
1667 // Modules are nested deep, so change the path to reference the same schema everywhere.
1668 schema_path = save_path.contains("modules/") ? "../../../doc/class.xsd" : "../class.xsd";
1669 } else {
1670 schema_path = "https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd";
1671 }
1672 header += vformat(
1673 R"( xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="%s">)",
1674 schema_path);
1675 _write_string(f, 0, header);
1676
1677 _write_string(f, 1, "<brief_description>");
1678 _write_string(f, 2, _translate_doc_string(c.brief_description).strip_edges().xml_escape());
1679 _write_string(f, 1, "</brief_description>");
1680
1681 _write_string(f, 1, "<description>");
1682 _write_string(f, 2, _translate_doc_string(c.description).strip_edges().xml_escape());
1683 _write_string(f, 1, "</description>");
1684
1685 _write_string(f, 1, "<tutorials>");
1686 for (int i = 0; i < c.tutorials.size(); i++) {
1687 DocData::TutorialDoc tutorial = c.tutorials.get(i);
1688 String title_attribute = (!tutorial.title.is_empty()) ? " title=\"" + _translate_doc_string(tutorial.title).xml_escape(true) + "\"" : "";
1689 _write_string(f, 2, "<link" + title_attribute + ">" + tutorial.link.xml_escape() + "</link>");
1690 }
1691 _write_string(f, 1, "</tutorials>");
1692
1693 _write_method_doc(f, "constructor", c.constructors);
1694
1695 _write_method_doc(f, "method", c.methods);
1696
1697 if (!c.properties.is_empty()) {
1698 _write_string(f, 1, "<members>");
1699
1700 for (int i = 0; i < c.properties.size(); i++) {
1701 String additional_attributes;
1702 if (!c.properties[i].enumeration.is_empty()) {
1703 additional_attributes += " enum=\"" + c.properties[i].enumeration.xml_escape(true) + "\"";
1704 if (c.properties[i].is_bitfield) {
1705 additional_attributes += " is_bitfield=\"true\"";
1706 }
1707 }
1708 if (!c.properties[i].default_value.is_empty()) {
1709 additional_attributes += " default=\"" + c.properties[i].default_value.xml_escape(true) + "\"";
1710 }
1711 if (c.properties[i].is_deprecated) {
1712 additional_attributes += " deprecated=\"" + c.properties[i].deprecated_message.xml_escape(true) + "\"";
1713 }
1714 if (c.properties[i].is_experimental) {
1715 additional_attributes += " experimental=\"" + c.properties[i].experimental_message.xml_escape(true) + "\"";
1716 }
1717 if (!c.properties[i].keywords.is_empty()) {
1718 additional_attributes += String(" keywords=\"") + c.properties[i].keywords.xml_escape(true) + "\"";
1719 }
1720
1721 const DocData::PropertyDoc &p = c.properties[i];
1722
1723 if (c.properties[i].overridden) {
1724 _write_string(f, 2, "<member name=\"" + p.name.xml_escape(true) + "\" type=\"" + p.type.xml_escape(true) + "\" setter=\"" + p.setter.xml_escape(true) + "\" getter=\"" + p.getter.xml_escape(true) + "\" overrides=\"" + p.overrides.xml_escape(true) + "\"" + additional_attributes + " />");
1725 } else {
1726 _write_string(f, 2, "<member name=\"" + p.name.xml_escape(true) + "\" type=\"" + p.type.xml_escape(true) + "\" setter=\"" + p.setter.xml_escape(true) + "\" getter=\"" + p.getter.xml_escape(true) + "\"" + additional_attributes + ">");
1727 _write_string(f, 3, _translate_doc_string(p.description).strip_edges().xml_escape());
1728 _write_string(f, 2, "</member>");
1729 }
1730 }
1731 _write_string(f, 1, "</members>");
1732 }
1733
1734 _write_method_doc(f, "signal", c.signals);
1735
1736 if (!c.constants.is_empty()) {
1737 _write_string(f, 1, "<constants>");
1738 for (int i = 0; i < c.constants.size(); i++) {
1739 const DocData::ConstantDoc &k = c.constants[i];
1740
1741 String additional_attributes;
1742 if (c.constants[i].is_deprecated) {
1743 additional_attributes += " deprecated=\"" + c.constants[i].deprecated_message.xml_escape(true) + "\"";
1744 }
1745 if (c.constants[i].is_experimental) {
1746 additional_attributes += " experimental=\"" + c.constants[i].experimental_message.xml_escape(true) + "\"";
1747 }
1748 if (!c.constants[i].keywords.is_empty()) {
1749 additional_attributes += String(" keywords=\"") + c.constants[i].keywords.xml_escape(true) + "\"";
1750 }
1751
1752 if (k.is_value_valid) {
1753 if (!k.enumeration.is_empty()) {
1754 if (k.is_bitfield) {
1755 _write_string(f, 2, "<constant name=\"" + k.name.xml_escape(true) + "\" value=\"" + k.value.xml_escape(true) + "\" enum=\"" + k.enumeration.xml_escape(true) + "\" is_bitfield=\"true\"" + additional_attributes + ">");
1756 } else {
1757 _write_string(f, 2, "<constant name=\"" + k.name.xml_escape(true) + "\" value=\"" + k.value.xml_escape(true) + "\" enum=\"" + k.enumeration.xml_escape(true) + "\"" + additional_attributes + ">");
1758 }
1759 } else {
1760 _write_string(f, 2, "<constant name=\"" + k.name.xml_escape(true) + "\" value=\"" + k.value.xml_escape(true) + "\"" + additional_attributes + ">");
1761 }
1762 } else {
1763 if (!k.enumeration.is_empty()) {
1764 _write_string(f, 2, "<constant name=\"" + k.name.xml_escape(true) + "\" value=\"platform-dependent\" enum=\"" + k.enumeration.xml_escape(true) + "\"" + additional_attributes + ">");
1765 } else {
1766 _write_string(f, 2, "<constant name=\"" + k.name.xml_escape(true) + "\" value=\"platform-dependent\"" + additional_attributes + ">");
1767 }
1768 }
1769 _write_string(f, 3, _translate_doc_string(k.description).strip_edges().xml_escape());
1770 _write_string(f, 2, "</constant>");
1771 }
1772
1773 _write_string(f, 1, "</constants>");
1774 }
1775
1776 _write_method_doc(f, "annotation", c.annotations);
1777
1778 if (!c.theme_properties.is_empty()) {
1779 _write_string(f, 1, "<theme_items>");
1780 for (int i = 0; i < c.theme_properties.size(); i++) {
1781 const DocData::ThemeItemDoc &ti = c.theme_properties[i];
1782
1783 String additional_attributes;
1784 if (!ti.default_value.is_empty()) {
1785 additional_attributes += String(" default=\"") + ti.default_value.xml_escape(true) + "\"";
1786 }
1787 if (ti.is_deprecated) {
1788 additional_attributes += " deprecated=\"" + ti.deprecated_message.xml_escape(true) + "\"";
1789 }
1790 if (ti.is_experimental) {
1791 additional_attributes += " experimental=\"" + ti.experimental_message.xml_escape(true) + "\"";
1792 }
1793 if (!ti.keywords.is_empty()) {
1794 additional_attributes += String(" keywords=\"") + ti.keywords.xml_escape(true) + "\"";
1795 }
1796
1797 _write_string(f, 2, "<theme_item name=\"" + ti.name.xml_escape(true) + "\" data_type=\"" + ti.data_type.xml_escape(true) + "\" type=\"" + ti.type.xml_escape(true) + "\"" + additional_attributes + ">");
1798
1799 _write_string(f, 3, _translate_doc_string(ti.description).strip_edges().xml_escape());
1800
1801 _write_string(f, 2, "</theme_item>");
1802 }
1803 _write_string(f, 1, "</theme_items>");
1804 }
1805
1806 _write_method_doc(f, "operator", c.operators);
1807
1808 _write_string(f, 0, "</class>");
1809 }
1810
1811 return OK;
1812 }
1813
1814 Error DocTools::load_compressed(const uint8_t *p_data, int64_t p_compressed_size, int64_t p_uncompressed_size) {
1815 Vector<uint8_t> data;
1816 data.resize(p_uncompressed_size);
1817 const int64_t ret = Compression::decompress(data.ptrw(), p_uncompressed_size, p_data, p_compressed_size, Compression::MODE_DEFLATE);
1818 ERR_FAIL_COND_V_MSG(ret == -1, ERR_FILE_CORRUPT, "Compressed file is corrupt.");
1819 class_list.clear();
1820
1821 Ref<XMLParser> parser = memnew(XMLParser);
1822 Error err = parser->open_buffer(data);
1823 if (err) {
1824 return err;
1825 }
1826
1827 _load(parser);
1828
1829 return OK;
1830 }
1831
1832 Error DocTools::load_xml(const uint8_t *p_data, int64_t p_size) {
1833 Ref<XMLParser> parser = memnew(XMLParser);
1834 Error err = parser->_open_buffer(p_data, p_size);
1835 if (err) {
1836 return err;
1837 }
1838
1839 _load(parser);
1840
1841 return OK;
1842 }