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