summaryrefslogtreecommitdiff
path: root/editor/doc_tools.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/doc_tools.cpp')
-rw-r--r--editor/doc_tools.cpp236
1 files changed, 124 insertions, 112 deletions
diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp
index 8d1c22dabd..ec162231e9 100644
--- a/editor/doc_tools.cpp
+++ b/editor/doc_tools.cpp
@@ -64,35 +64,42 @@ 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) {
- if (cf.methods[j].arguments[k].type == m.arguments[l].type && !arg_used[l]) {
- arg_used.write[l] = true;
- break;
+ 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 (!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];
@@ -270,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;
}
@@ -427,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);
}
@@ -867,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);
@@ -1151,6 +1173,59 @@ static void _write_string(FileAccess *f, int p_tablevel, const String &p_string)
f->store_string(tab + p_string + "\n");
}
+static void _write_method_doc(FileAccess *f, const String &p_name, Vector<DocData::MethodDoc> &p_method_docs) {
+ if (!p_method_docs.is_empty()) {
+ p_method_docs.sort();
+ _write_string(f, 1, "<" + p_name + "s>");
+ for (int i = 0; i < p_method_docs.size(); i++) {
+ const DocData::MethodDoc &m = p_method_docs[i];
+
+ String qualifiers;
+ if (m.qualifiers != "") {
+ qualifiers += " qualifiers=\"" + m.qualifiers.xml_escape() + "\"";
+ }
+
+ _write_string(f, 2, "<" + p_name + " name=\"" + m.name.xml_escape() + "\"" + qualifiers + ">");
+
+ if (m.return_type != "") {
+ String enum_text;
+ if (m.return_enum != String()) {
+ enum_text = " enum=\"" + m.return_enum + "\"";
+ }
+ _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];
+
+ String enum_text;
+ if (a.enumeration != String()) {
+ enum_text = " enum=\"" + a.enumeration + "\"";
+ }
+
+ if (a.default_value != "") {
+ _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " default=\"" + a.default_value.xml_escape(true) + "\" />");
+ } else {
+ _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " />");
+ }
+ }
+
+ _write_string(f, 3, "<description>");
+ _write_string(f, 4, m.description.strip_edges().xml_escape());
+ _write_string(f, 3, "</description>");
+
+ _write_string(f, 2, "</" + p_name + ">");
+ }
+
+ _write_string(f, 1, "</" + p_name + "s>");
+ }
+}
+
Error DocTools::save_classes(const String &p_default_path, const Map<String, String> &p_class_path) {
for (Map<String, DocData::ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
DocData::ClassDoc &c = E->get();
@@ -1194,53 +1269,9 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str
}
_write_string(f, 1, "</tutorials>");
- _write_string(f, 1, "<methods>");
-
- c.methods.sort();
-
- for (int i = 0; i < c.methods.size(); i++) {
- const DocData::MethodDoc &m = c.methods[i];
-
- String qualifiers;
- if (m.qualifiers != "") {
- qualifiers += " qualifiers=\"" + m.qualifiers.xml_escape() + "\"";
- }
-
- _write_string(f, 2, "<method name=\"" + m.name.xml_escape() + "\"" + qualifiers + ">");
-
- if (m.return_type != "") {
- String enum_text;
- if (m.return_enum != String()) {
- enum_text = " enum=\"" + m.return_enum + "\"";
- }
- _write_string(f, 3, "<return type=\"" + m.return_type + "\"" + enum_text + " />");
- }
-
- for (int j = 0; j < m.arguments.size(); j++) {
- const DocData::ArgumentDoc &a = m.arguments[j];
-
- String enum_text;
- if (a.enumeration != String()) {
- enum_text = " enum=\"" + a.enumeration + "\"";
- }
-
- if (a.default_value != "") {
- _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " default=\"" + a.default_value.xml_escape(true) + "\" />");
- } else {
- _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " />");
- }
- }
-
- _write_string(f, 3, "<description>");
- _write_string(f, 4, m.description.strip_edges().xml_escape());
- _write_string(f, 3, "</description>");
-
- _write_string(f, 2, "</method>");
- }
-
- _write_string(f, 1, "</methods>");
+ _write_method_doc(f, "method", c.methods);
- if (c.properties.size()) {
+ if (!c.properties.is_empty()) {
_write_string(f, 1, "<members>");
c.properties.sort();
@@ -1267,52 +1298,33 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str
_write_string(f, 1, "</members>");
}
- if (c.signals.size()) {
- c.signals.sort();
-
- _write_string(f, 1, "<signals>");
- for (int i = 0; i < c.signals.size(); i++) {
- const DocData::MethodDoc &m = c.signals[i];
- _write_string(f, 2, "<signal name=\"" + m.name + "\">");
- for (int j = 0; j < m.arguments.size(); j++) {
- const DocData::ArgumentDoc &a = m.arguments[j];
- _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\" />");
- }
-
- _write_string(f, 3, "<description>");
- _write_string(f, 4, m.description.strip_edges().xml_escape());
- _write_string(f, 3, "</description>");
-
- _write_string(f, 2, "</signal>");
- }
-
- _write_string(f, 1, "</signals>");
- }
-
- _write_string(f, 1, "<constants>");
+ _write_method_doc(f, "signal", c.signals);
- for (int i = 0; i < c.constants.size(); i++) {
- const DocData::ConstantDoc &k = c.constants[i];
- if (k.is_value_valid) {
- if (k.enumeration != String()) {
- _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">");
- } else {
- _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\">");
- }
- } else {
- if (k.enumeration != String()) {
- _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\" enum=\"" + k.enumeration + "\">");
+ if (!c.constants.is_empty()) {
+ _write_string(f, 1, "<constants>");
+ for (int i = 0; i < c.constants.size(); i++) {
+ const DocData::ConstantDoc &k = c.constants[i];
+ if (k.is_value_valid) {
+ if (k.enumeration != String()) {
+ _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">");
+ } else {
+ _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\">");
+ }
} else {
- _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\">");
+ if (k.enumeration != String()) {
+ _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\" enum=\"" + k.enumeration + "\">");
+ } else {
+ _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\">");
+ }
}
+ _write_string(f, 3, k.description.strip_edges().xml_escape());
+ _write_string(f, 2, "</constant>");
}
- _write_string(f, 3, k.description.strip_edges().xml_escape());
- _write_string(f, 2, "</constant>");
- }
- _write_string(f, 1, "</constants>");
+ _write_string(f, 1, "</constants>");
+ }
- if (c.theme_properties.size()) {
+ if (!c.theme_properties.is_empty()) {
c.theme_properties.sort();
_write_string(f, 1, "<theme_items>");