diff options
Diffstat (limited to 'editor/doc_tools.cpp')
-rw-r--r-- | editor/doc_tools.cpp | 182 |
1 files changed, 107 insertions, 75 deletions
diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index c752d0d4fd..d04875f188 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -64,36 +64,43 @@ void DocTools::merge_from(const DocTools &p_data) { if (cf.methods[j].name != m.name) { continue; } - if (cf.methods[j].arguments.size() != m.arguments.size()) { - continue; - } - // since polymorphic functions are allowed we need to check the type of - // the arguments so we make sure they are different. - int arg_count = cf.methods[j].arguments.size(); - Vector<bool> arg_used; - arg_used.resize(arg_count); - for (int l = 0; l < arg_count; ++l) { - arg_used.write[l] = false; - } - // also there is no guarantee that argument ordering will match, so we - // have to check one by one so we make sure we have an exact match - for (int k = 0; k < arg_count; ++k) { + + const char *operator_prefix = "operator "; // Operators use a space at the end, making this prefix an invalid identifier (and differentiating from methods). + + if (cf.methods[j].name == c.name || cf.methods[j].name.begins_with(operator_prefix)) { + // Since constructors and operators can repeat, we need to check the type of + // the arguments so we make sure they are different. + + if (cf.methods[j].arguments.size() != m.arguments.size()) { + continue; + } + + int arg_count = cf.methods[j].arguments.size(); + Vector<bool> arg_used; + arg_used.resize(arg_count); + for (int l = 0; l < arg_count; ++l) { + arg_used.write[l] = false; + } + // also there is no guarantee that argument ordering will match, so we + // have to check one by one so we make sure we have an exact match + for (int k = 0; k < arg_count; ++k) { + for (int l = 0; l < arg_count; ++l) { + if (cf.methods[j].arguments[k].type == m.arguments[l].type && !arg_used[l]) { + arg_used.write[l] = true; + break; + } + } + } + bool not_the_same = false; for (int l = 0; l < arg_count; ++l) { - if (cf.methods[j].arguments[k].type == m.arguments[l].type && !arg_used[l]) { - arg_used.write[l] = true; - break; + if (!arg_used[l]) { // at least one of the arguments was different + not_the_same = true; } } - } - bool not_the_same = false; - for (int l = 0; l < arg_count; ++l) { - if (!arg_used[l]) { // at least one of the arguments was different - not_the_same = true; + if (not_the_same) { + continue; } } - if (not_the_same) { - continue; - } const DocData::MethodDoc &mf = cf.methods[j]; @@ -145,15 +152,15 @@ void DocTools::merge_from(const DocTools &p_data) { } for (int i = 0; i < c.theme_properties.size(); i++) { - DocData::PropertyDoc &p = c.theme_properties.write[i]; + DocData::ThemeItemDoc &ti = c.theme_properties.write[i]; for (int j = 0; j < cf.theme_properties.size(); j++) { - if (cf.theme_properties[j].name != p.name) { + if (cf.theme_properties[j].name != ti.name || cf.theme_properties[j].data_type != ti.data_type) { continue; } - const DocData::PropertyDoc &pf = cf.theme_properties[j]; + const DocData::ThemeItemDoc &pf = cf.theme_properties[j]; - p.description = pf.description; + ti.description = pf.description; break; } } @@ -245,9 +252,6 @@ void DocTools::generate(bool p_basic_types) { } String cname = name; - if (cname.begins_with("_")) { //proxy class - cname = cname.substr(1, name.length()); - } class_list[cname] = DocData::ClassDoc(); DocData::ClassDoc &c = class_list[cname]; @@ -273,7 +277,7 @@ void DocTools::generate(bool p_basic_types) { EO = EO->next(); } - if (E.usage & PROPERTY_USAGE_GROUP || E.usage & PROPERTY_USAGE_SUBGROUP || E.usage & PROPERTY_USAGE_CATEGORY || E.usage & PROPERTY_USAGE_INTERNAL) { + 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)) { continue; } @@ -430,6 +434,18 @@ void DocTools::generate(bool p_basic_types) { } } + Vector<Error> errs = ClassDB::get_method_error_return_values(name, E.name); + if (errs.size()) { + if (errs.find(OK) == -1) { + errs.insert(0, OK); + } + for (int i = 0; i < errs.size(); i++) { + if (method.errors_returned.find(errs[i]) == -1) { + method.errors_returned.push_back(errs[i]); + } + } + } + c.methods.push_back(method); } @@ -464,60 +480,69 @@ void DocTools::generate(bool p_basic_types) { c.constants.push_back(constant); } - //theme stuff - + // Theme items. { List<StringName> l; - Theme::get_default()->get_constant_list(cname, &l); - for (const StringName &E : l) { - DocData::PropertyDoc pd; - pd.name = E; - pd.type = "int"; - pd.default_value = itos(Theme::get_default()->get_constant(E, cname)); - c.theme_properties.push_back(pd); - } - l.clear(); Theme::get_default()->get_color_list(cname, &l); for (const StringName &E : l) { - DocData::PropertyDoc pd; - pd.name = E; - pd.type = "Color"; - pd.default_value = Variant(Theme::get_default()->get_color(E, cname)).get_construct_string(); - c.theme_properties.push_back(pd); + DocData::ThemeItemDoc tid; + tid.name = E; + tid.type = "Color"; + tid.data_type = "color"; + tid.default_value = Variant(Theme::get_default()->get_color(E, cname)).get_construct_string(); + c.theme_properties.push_back(tid); } l.clear(); - Theme::get_default()->get_icon_list(cname, &l); + Theme::get_default()->get_constant_list(cname, &l); for (const StringName &E : l) { - DocData::PropertyDoc pd; - pd.name = E; - pd.type = "Texture2D"; - c.theme_properties.push_back(pd); + DocData::ThemeItemDoc tid; + tid.name = E; + tid.type = "int"; + tid.data_type = "constant"; + tid.default_value = itos(Theme::get_default()->get_constant(E, cname)); + c.theme_properties.push_back(tid); } + l.clear(); Theme::get_default()->get_font_list(cname, &l); for (const StringName &E : l) { - DocData::PropertyDoc pd; - pd.name = E; - pd.type = "Font"; - c.theme_properties.push_back(pd); + DocData::ThemeItemDoc tid; + tid.name = E; + tid.type = "Font"; + tid.data_type = "font"; + c.theme_properties.push_back(tid); } + l.clear(); Theme::get_default()->get_font_size_list(cname, &l); for (const StringName &E : l) { - DocData::PropertyDoc pd; - pd.name = E; - pd.type = "int"; - c.theme_properties.push_back(pd); + DocData::ThemeItemDoc tid; + tid.name = E; + tid.type = "int"; + tid.data_type = "font_size"; + c.theme_properties.push_back(tid); } + + l.clear(); + Theme::get_default()->get_icon_list(cname, &l); + for (const StringName &E : l) { + DocData::ThemeItemDoc tid; + tid.name = E; + tid.type = "Texture2D"; + tid.data_type = "icon"; + c.theme_properties.push_back(tid); + } + l.clear(); Theme::get_default()->get_stylebox_list(cname, &l); for (const StringName &E : l) { - DocData::PropertyDoc pd; - pd.name = E; - pd.type = "StyleBox"; - c.theme_properties.push_back(pd); + DocData::ThemeItemDoc tid; + tid.name = E; + tid.type = "StyleBox"; + tid.data_type = "style"; + c.theme_properties.push_back(tid); } } @@ -731,9 +756,6 @@ void DocTools::generate(bool p_basic_types) { while (String(ClassDB::get_parent_class(pd.type)) != "Object") { pd.type = ClassDB::get_parent_class(pd.type); } - if (pd.type.begins_with("_")) { - pd.type = pd.type.substr(1, pd.type.length()); - } c.properties.push_back(pd); } @@ -864,6 +886,9 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> & if (parser->has_attribute("enum")) { method.return_enum = parser->get_attribute_value("enum"); } + } else if (name == "returns_error") { + ERR_FAIL_COND_V(!parser->has_attribute("number"), ERR_FILE_CORRUPT); + method.errors_returned.push_back(parser->get_attribute_value("number").to_int()); } else if (name == "argument") { DocData::ArgumentDoc argument; ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT); @@ -1069,12 +1094,14 @@ Error DocTools::_load(Ref<XMLParser> parser) { String name3 = parser->get_node_name(); if (name3 == "theme_item") { - DocData::PropertyDoc prop2; + DocData::ThemeItemDoc prop2; ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT); prop2.name = parser->get_attribute_value("name"); ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT); prop2.type = parser->get_attribute_value("type"); + ERR_FAIL_COND_V(!parser->has_attribute("data_type"), ERR_FILE_CORRUPT); + prop2.data_type = parser->get_attribute_value("data_type"); if (!parser->is_empty()) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) { @@ -1210,6 +1237,11 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str } _write_string(f, 3, "<return type=\"" + m.return_type + "\"" + enum_text + " />"); } + if (m.errors_returned.size() > 0) { + for (int j = 0; j < m.errors_returned.size(); j++) { + _write_string(f, 3, "<returns_error number=\"" + itos(m.errors_returned[j]) + "\"/>"); + } + } for (int j = 0; j < m.arguments.size(); j++) { const DocData::ArgumentDoc &a = m.arguments[j]; @@ -1312,15 +1344,15 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str _write_string(f, 1, "<theme_items>"); for (int i = 0; i < c.theme_properties.size(); i++) { - const DocData::PropertyDoc &p = c.theme_properties[i]; + const DocData::ThemeItemDoc &ti = c.theme_properties[i]; - if (p.default_value != "") { - _write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\" default=\"" + p.default_value.xml_escape(true) + "\">"); + if (ti.default_value != "") { + _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=\"" + p.name + "\" type=\"" + p.type + "\">"); + _write_string(f, 2, "<theme_item name=\"" + ti.name + "\" data_type=\"" + ti.data_type + "\" type=\"" + ti.type + "\">"); } - _write_string(f, 3, p.description.strip_edges().xml_escape()); + _write_string(f, 3, ti.description.strip_edges().xml_escape()); _write_string(f, 2, "</theme_item>"); } |