diff options
Diffstat (limited to 'editor/doc_tools.cpp')
| -rw-r--r-- | editor/doc_tools.cpp | 193 |
1 files changed, 154 insertions, 39 deletions
diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index 9c1fc2a8bf..ee3e54e9df 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -87,7 +87,10 @@ void DocTools::merge_from(const DocTools &p_data) { const DocData::ClassDoc &cf = p_data.class_list[c.name]; c.is_deprecated = cf.is_deprecated; + c.deprecated_message = cf.deprecated_message; c.is_experimental = cf.is_experimental; + c.experimental_message = cf.experimental_message; + c.keywords = cf.keywords; c.description = cf.description; c.brief_description = cf.brief_description; @@ -138,7 +141,9 @@ void DocTools::merge_from(const DocTools &p_data) { m.description = mf.description; m.is_deprecated = mf.is_deprecated; + m.deprecated_message = mf.deprecated_message; m.is_experimental = mf.is_experimental; + m.experimental_message = mf.experimental_message; break; } } @@ -155,7 +160,10 @@ void DocTools::merge_from(const DocTools &p_data) { m.description = mf.description; m.is_deprecated = mf.is_deprecated; + m.deprecated_message = mf.deprecated_message; m.is_experimental = mf.is_experimental; + m.experimental_message = mf.experimental_message; + m.keywords = mf.keywords; break; } } @@ -171,7 +179,10 @@ void DocTools::merge_from(const DocTools &p_data) { m.description = mf.description; m.is_deprecated = mf.is_deprecated; + m.deprecated_message = mf.deprecated_message; m.is_experimental = mf.is_experimental; + m.experimental_message = mf.experimental_message; + m.keywords = mf.keywords; break; } } @@ -187,7 +198,10 @@ void DocTools::merge_from(const DocTools &p_data) { m.description = mf.description; m.is_deprecated = mf.is_deprecated; + m.deprecated_message = mf.deprecated_message; m.is_experimental = mf.is_experimental; + m.experimental_message = mf.experimental_message; + m.keywords = mf.keywords; break; } } @@ -203,7 +217,10 @@ void DocTools::merge_from(const DocTools &p_data) { m.description = mf.description; m.is_deprecated = mf.is_deprecated; + m.deprecated_message = mf.deprecated_message; m.is_experimental = mf.is_experimental; + m.experimental_message = mf.experimental_message; + m.keywords = mf.keywords; break; } } @@ -219,7 +236,10 @@ void DocTools::merge_from(const DocTools &p_data) { p.description = pf.description; p.is_deprecated = pf.is_deprecated; + p.deprecated_message = pf.deprecated_message; p.is_experimental = pf.is_experimental; + p.experimental_message = pf.experimental_message; + p.keywords = pf.keywords; break; } } @@ -234,6 +254,7 @@ void DocTools::merge_from(const DocTools &p_data) { const DocData::ThemeItemDoc &pf = cf.theme_properties[j]; ti.description = pf.description; + ti.keywords = pf.keywords; break; } } @@ -283,7 +304,9 @@ void DocTools::merge_from(const DocTools &p_data) { m.description = mf.description; m.is_deprecated = mf.is_deprecated; + m.deprecated_message = mf.deprecated_message; m.is_experimental = mf.is_experimental; + m.experimental_message = mf.experimental_message; break; } } @@ -307,21 +330,21 @@ void DocTools::merge_from(const DocTools &p_data) { } } -void DocTools::remove_from(const DocTools &p_data) { - for (const KeyValue<String, DocData::ClassDoc> &E : p_data.class_list) { - if (class_list.has(E.key)) { - class_list.erase(E.key); - } - } -} - void DocTools::add_doc(const DocData::ClassDoc &p_class_doc) { ERR_FAIL_COND(p_class_doc.name.is_empty()); class_list[p_class_doc.name] = p_class_doc; + inheriting[p_class_doc.inherits].insert(p_class_doc.name); } void DocTools::remove_doc(const String &p_class_name) { ERR_FAIL_COND(p_class_name.is_empty() || !class_list.has(p_class_name)); + const String &inherits = class_list[p_class_name].inherits; + if (inheriting.has(inherits)) { + inheriting[inherits].erase(p_class_name); + if (inheriting[inherits].is_empty()) { + inheriting.erase(inherits); + } + } class_list.erase(p_class_name); } @@ -391,6 +414,8 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { c.name = cname; c.inherits = ClassDB::get_parent_class(name); + inheriting[c.inherits].insert(cname); + List<PropertyInfo> properties; List<PropertyInfo> own_properties; @@ -632,7 +657,7 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { // Theme items. { List<ThemeDB::ThemeItemBind> theme_items; - ThemeDB::get_singleton()->get_class_own_items(cname, &theme_items); + ThemeDB::get_singleton()->get_class_items(cname, &theme_items); Ref<Theme> default_theme = ThemeDB::get_singleton()->get_default_theme(); for (const ThemeDB::ThemeItemBind &theme_item : theme_items) { @@ -692,6 +717,7 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { // it's not a ClassDB-exposed class. class_list["Variant"] = DocData::ClassDoc(); class_list["Variant"].name = "Variant"; + inheriting[""].insert("Variant"); } // Add Variant data types. @@ -709,6 +735,8 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { DocData::ClassDoc &c = class_list[cname]; c.name = cname; + inheriting[""].insert(cname); + Callable::CallError cerror; Variant v; Variant::construct(Variant::Type(i), v, nullptr, 0, cerror); @@ -870,6 +898,8 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { DocData::ClassDoc &c = class_list[cname]; c.name = cname; + inheriting[""].insert(cname); + // Global constants. for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) { DocData::ConstantDoc cd; @@ -953,6 +983,8 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { DocData::ClassDoc c; c.name = cname; + inheriting[""].insert(cname); + // Get functions. List<MethodInfo> minfo; lang->get_public_functions(&minfo); @@ -1052,12 +1084,25 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> & if (parser->has_attribute("qualifiers")) { method.qualifiers = parser->get_named_attribute_value("qualifiers"); } +#ifndef DISABLE_DEPRECATED if (parser->has_attribute("is_deprecated")) { method.is_deprecated = parser->get_named_attribute_value("is_deprecated").to_lower() == "true"; } if (parser->has_attribute("is_experimental")) { method.is_experimental = parser->get_named_attribute_value("is_experimental").to_lower() == "true"; } +#endif + if (parser->has_attribute("deprecated")) { + method.is_deprecated = true; + method.deprecated_message = parser->get_named_attribute_value("deprecated"); + } + if (parser->has_attribute("experimental")) { + method.is_experimental = true; + method.experimental_message = parser->get_named_attribute_value("experimental"); + } + if (parser->has_attribute("keywords")) { + method.keywords = parser->get_named_attribute_value("keywords"); + } while (parser->read() == OK) { if (parser->get_node_type() == XMLParser::NODE_ELEMENT) { @@ -1195,13 +1240,28 @@ Error DocTools::_load(Ref<XMLParser> parser) { c.inherits = parser->get_named_attribute_value("inherits"); } + inheriting[c.inherits].insert(name); + +#ifndef DISABLE_DEPRECATED if (parser->has_attribute("is_deprecated")) { c.is_deprecated = parser->get_named_attribute_value("is_deprecated").to_lower() == "true"; } - if (parser->has_attribute("is_experimental")) { c.is_experimental = parser->get_named_attribute_value("is_experimental").to_lower() == "true"; } +#endif + if (parser->has_attribute("deprecated")) { + c.is_deprecated = true; + c.deprecated_message = parser->get_named_attribute_value("deprecated"); + } + if (parser->has_attribute("experimental")) { + c.is_experimental = true; + c.experimental_message = parser->get_named_attribute_value("experimental"); + } + + if (parser->has_attribute("keywords")) { + c.keywords = parser->get_named_attribute_value("keywords"); + } while (parser->read() == OK) { if (parser->get_node_type() == XMLParser::NODE_ELEMENT) { @@ -1279,12 +1339,25 @@ Error DocTools::_load(Ref<XMLParser> parser) { prop2.is_bitfield = parser->get_named_attribute_value("is_bitfield").to_lower() == "true"; } } +#ifndef DISABLE_DEPRECATED if (parser->has_attribute("is_deprecated")) { prop2.is_deprecated = parser->get_named_attribute_value("is_deprecated").to_lower() == "true"; } if (parser->has_attribute("is_experimental")) { prop2.is_experimental = parser->get_named_attribute_value("is_experimental").to_lower() == "true"; } +#endif + if (parser->has_attribute("deprecated")) { + prop2.is_deprecated = true; + prop2.deprecated_message = parser->get_named_attribute_value("deprecated"); + } + if (parser->has_attribute("experimental")) { + prop2.is_experimental = true; + prop2.experimental_message = parser->get_named_attribute_value("experimental"); + } + if (parser->has_attribute("keywords")) { + prop2.keywords = parser->get_named_attribute_value("keywords"); + } if (!parser->is_empty()) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) { @@ -1315,6 +1388,9 @@ Error DocTools::_load(Ref<XMLParser> parser) { prop2.type = parser->get_named_attribute_value("type"); ERR_FAIL_COND_V(!parser->has_attribute("data_type"), ERR_FILE_CORRUPT); prop2.data_type = parser->get_named_attribute_value("data_type"); + if (parser->has_attribute("keywords")) { + prop2.keywords = parser->get_named_attribute_value("keywords"); + } if (!parser->is_empty()) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) { @@ -1349,12 +1425,25 @@ Error DocTools::_load(Ref<XMLParser> parser) { constant2.is_bitfield = parser->get_named_attribute_value("is_bitfield").to_lower() == "true"; } } +#ifndef DISABLE_DEPRECATED if (parser->has_attribute("is_deprecated")) { constant2.is_deprecated = parser->get_named_attribute_value("is_deprecated").to_lower() == "true"; } if (parser->has_attribute("is_experimental")) { constant2.is_experimental = parser->get_named_attribute_value("is_experimental").to_lower() == "true"; } +#endif + if (parser->has_attribute("deprecated")) { + constant2.is_deprecated = true; + constant2.deprecated_message = parser->get_named_attribute_value("deprecated"); + } + if (parser->has_attribute("experimental")) { + constant2.is_experimental = true; + constant2.experimental_message = parser->get_named_attribute_value("experimental"); + } + if (parser->has_attribute("keywords")) { + constant2.keywords = parser->get_named_attribute_value("keywords"); + } if (!parser->is_empty()) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) { @@ -1399,25 +1488,26 @@ static void _write_method_doc(Ref<FileAccess> f, const String &p_name, Vector<Do for (int i = 0; i < p_method_docs.size(); i++) { const DocData::MethodDoc &m = p_method_docs[i]; - String qualifiers; + String additional_attributes; if (!m.qualifiers.is_empty()) { - qualifiers += " qualifiers=\"" + m.qualifiers.xml_escape() + "\""; + additional_attributes += " qualifiers=\"" + m.qualifiers.xml_escape(true) + "\""; } - - String additional_attributes; if (m.is_deprecated) { - additional_attributes += " is_deprecated=\"true\""; + additional_attributes += " deprecated=\"" + m.deprecated_message.xml_escape(true) + "\""; } if (m.is_experimental) { - additional_attributes += " is_experimental=\"true\""; + additional_attributes += " experimental=\"" + m.experimental_message.xml_escape(true) + "\""; + } + if (!m.keywords.is_empty()) { + additional_attributes += String(" keywords=\"") + m.keywords.xml_escape(true) + "\""; } - _write_string(f, 2, "<" + p_name + " name=\"" + m.name.xml_escape() + "\"" + qualifiers + additional_attributes + ">"); + _write_string(f, 2, "<" + p_name + " name=\"" + m.name.xml_escape(true) + "\"" + additional_attributes + ">"); if (!m.return_type.is_empty()) { String enum_text; if (!m.return_enum.is_empty()) { - enum_text = " enum=\"" + m.return_enum + "\""; + enum_text = " enum=\"" + m.return_enum.xml_escape(true) + "\""; if (m.return_is_bitfield) { enum_text += " is_bitfield=\"true\""; } @@ -1435,16 +1525,16 @@ static void _write_method_doc(Ref<FileAccess> f, const String &p_name, Vector<Do String enum_text; if (!a.enumeration.is_empty()) { - enum_text = " enum=\"" + a.enumeration + "\""; + enum_text = " enum=\"" + a.enumeration.xml_escape(true) + "\""; if (a.is_bitfield) { enum_text += " is_bitfield=\"true\""; } } if (!a.default_value.is_empty()) { - _write_string(f, 3, "<param index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape(true) + "\"" + enum_text + " default=\"" + a.default_value.xml_escape(true) + "\" />"); + _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) + "\" />"); } else { - _write_string(f, 3, "<param index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape(true) + "\"" + enum_text + " />"); + _write_string(f, 3, "<param index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape(true) + "\" type=\"" + a.type.xml_escape(true) + "\"" + enum_text + " />"); } } @@ -1482,12 +1572,15 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, if (!c.inherits.is_empty()) { header += " inherits=\"" + c.inherits.xml_escape(true) + "\""; if (c.is_deprecated) { - header += " is_deprecated=\"true\""; + header += " deprecated=\"" + c.deprecated_message.xml_escape(true) + "\""; } if (c.is_experimental) { - header += " is_experimental=\"true\""; + header += " experimental=\"" + c.experimental_message.xml_escape(true) + "\""; } } + if (!c.keywords.is_empty()) { + header += String(" keywords=\"") + c.keywords.xml_escape(true) + "\""; + } if (p_include_xml_schema) { // Reference the XML schema so editors can provide error checking. // Modules are nested deep, so change the path to reference the same schema everywhere. @@ -1510,7 +1603,7 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, _write_string(f, 1, "<tutorials>"); for (int i = 0; i < c.tutorials.size(); i++) { DocData::TutorialDoc tutorial = c.tutorials.get(i); - String title_attribute = (!tutorial.title.is_empty()) ? " title=\"" + _translate_doc_string(tutorial.title).xml_escape() + "\"" : ""; + String title_attribute = (!tutorial.title.is_empty()) ? " title=\"" + _translate_doc_string(tutorial.title).xml_escape(true) + "\"" : ""; _write_string(f, 2, "<link" + title_attribute + ">" + tutorial.link.xml_escape() + "</link>"); } _write_string(f, 1, "</tutorials>"); @@ -1527,7 +1620,7 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, for (int i = 0; i < c.properties.size(); i++) { String additional_attributes; if (!c.properties[i].enumeration.is_empty()) { - additional_attributes += " enum=\"" + c.properties[i].enumeration + "\""; + additional_attributes += " enum=\"" + c.properties[i].enumeration.xml_escape(true) + "\""; if (c.properties[i].is_bitfield) { additional_attributes += " is_bitfield=\"true\""; } @@ -1536,18 +1629,21 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, additional_attributes += " default=\"" + c.properties[i].default_value.xml_escape(true) + "\""; } if (c.properties[i].is_deprecated) { - additional_attributes += " is_deprecated=\"true\""; + additional_attributes += " deprecated=\"" + c.properties[i].deprecated_message.xml_escape(true) + "\""; } if (c.properties[i].is_experimental) { - additional_attributes += " is_experimental=\"true\""; + additional_attributes += " experimental=\"" + c.properties[i].experimental_message.xml_escape(true) + "\""; + } + if (!c.properties[i].keywords.is_empty()) { + additional_attributes += String(" keywords=\"") + c.properties[i].keywords.xml_escape(true) + "\""; } const DocData::PropertyDoc &p = c.properties[i]; if (c.properties[i].overridden) { - _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type.xml_escape(true) + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\" overrides=\"" + p.overrides + "\"" + additional_attributes + " />"); + _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 + " />"); } else { - _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type.xml_escape(true) + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\"" + additional_attributes + ">"); + _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 + ">"); _write_string(f, 3, _translate_doc_string(p.description).strip_edges().xml_escape()); _write_string(f, 2, "</member>"); } @@ -1564,27 +1660,30 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, String additional_attributes; if (c.constants[i].is_deprecated) { - additional_attributes += " is_deprecated=\"true\""; + additional_attributes += " deprecated=\"" + c.constants[i].deprecated_message.xml_escape(true) + "\""; } if (c.constants[i].is_experimental) { - additional_attributes += " is_experimental=\"true\""; + additional_attributes += " experimental=\"" + c.constants[i].experimental_message.xml_escape(true) + "\""; + } + if (!c.constants[i].keywords.is_empty()) { + additional_attributes += String(" keywords=\"") + c.constants[i].keywords.xml_escape(true) + "\""; } if (k.is_value_valid) { if (!k.enumeration.is_empty()) { if (k.is_bitfield) { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value.xml_escape(true) + "\" enum=\"" + k.enumeration + "\" is_bitfield=\"true\"" + additional_attributes + ">"); + _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 + ">"); } else { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value.xml_escape(true) + "\" enum=\"" + k.enumeration + "\"" + additional_attributes + ">"); + _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 + ">"); } } else { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value.xml_escape(true) + "\"" + additional_attributes + ">"); + _write_string(f, 2, "<constant name=\"" + k.name.xml_escape(true) + "\" value=\"" + k.value.xml_escape(true) + "\"" + additional_attributes + ">"); } } else { if (!k.enumeration.is_empty()) { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\" enum=\"" + k.enumeration + "\"" + additional_attributes + ">"); + _write_string(f, 2, "<constant name=\"" + k.name.xml_escape(true) + "\" value=\"platform-dependent\" enum=\"" + k.enumeration.xml_escape(true) + "\"" + additional_attributes + ">"); } else { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\"" + additional_attributes + ">"); + _write_string(f, 2, "<constant name=\"" + k.name.xml_escape(true) + "\" value=\"platform-dependent\"" + additional_attributes + ">"); } } _write_string(f, 3, _translate_doc_string(k.description).strip_edges().xml_escape()); @@ -1603,11 +1702,15 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, for (int i = 0; i < c.theme_properties.size(); i++) { const DocData::ThemeItemDoc &ti = c.theme_properties[i]; + String additional_attributes; if (!ti.default_value.is_empty()) { - _write_string(f, 2, "<theme_item name=\"" + ti.name + "\" data_type=\"" + ti.data_type + "\" type=\"" + ti.type + "\" default=\"" + ti.default_value.xml_escape(true) + "\">"); - } else { - _write_string(f, 2, "<theme_item name=\"" + ti.name + "\" data_type=\"" + ti.data_type + "\" type=\"" + ti.type + "\">"); + additional_attributes += String(" default=\"") + ti.default_value.xml_escape(true) + "\""; } + if (!ti.keywords.is_empty()) { + additional_attributes += String(" keywords=\"") + ti.keywords.xml_escape(true) + "\""; + } + + _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 + ">"); _write_string(f, 3, _translate_doc_string(ti.description).strip_edges().xml_escape()); @@ -1641,3 +1744,15 @@ Error DocTools::load_compressed(const uint8_t *p_data, int p_compressed_size, in return OK; } + +Error DocTools::load_xml(const uint8_t *p_data, int p_size) { + Ref<XMLParser> parser = memnew(XMLParser); + Error err = parser->_open_buffer(p_data, p_size); + if (err) { + return err; + } + + _load(parser); + + return OK; +} |
