Skip to content

Commit 414a497

Browse files
committed
Merge pull request godotengine#108489 from raulsntos/dotnet/fix-bindgen-errors
[.NET] Fix various errors in bindings generator
2 parents c74e872 + 1825146 commit 414a497

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

modules/mono/editor/bindings_generator.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ String BindingsGenerator::bbcode_to_text(const String &p_bbcode, const TypeInter
273273
target_cname = link_target_parts[0];
274274
}
275275

276-
if (link_tag == "method") {
276+
if (!_validate_api_type(target_itype, p_itype)) {
277+
// If the target member is referenced from a type with a different API level, we can't reference it.
278+
_append_text_undeclared(output, link_target);
279+
} else if (link_tag == "method") {
277280
_append_text_method(output, target_itype, target_cname, link_target, link_target_parts);
278281
} else if (link_tag == "constructor") {
279282
// TODO: Support constructors?
@@ -587,7 +590,10 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf
587590
target_cname = link_target_parts[0];
588591
}
589592

590-
if (link_tag == "method") {
593+
if (!_validate_api_type(target_itype, p_itype)) {
594+
// If the target member is referenced from a type with a different API level, we can't reference it.
595+
_append_xml_undeclared(xml_output, link_target);
596+
} else if (link_tag == "method") {
591597
_append_xml_method(xml_output, target_itype, target_cname, link_target, link_target_parts, p_itype);
592598
} else if (link_tag == "constructor") {
593599
// TODO: Support constructors?
@@ -831,6 +837,9 @@ void BindingsGenerator::_append_text_method(StringBuilder &p_output, const TypeI
831837
p_output.append("'new " BINDINGS_NAMESPACE ".");
832838
p_output.append(p_target_itype->proxy_name);
833839
p_output.append("()'");
840+
} else if (p_target_cname == "to_string") {
841+
// C# uses the built-in object.ToString() method, reference that instead.
842+
p_output.append("'object.ToString()'");
834843
} else {
835844
const MethodInterface *target_imethod = p_target_itype->find_method_by_name(p_target_cname);
836845

@@ -865,7 +874,7 @@ void BindingsGenerator::_append_text_method(StringBuilder &p_output, const TypeI
865874
}
866875
p_output.append(")'");
867876
} else {
868-
if (!p_target_itype->is_intentionally_ignored(p_link_target)) {
877+
if (!p_target_itype->is_intentionally_ignored(p_target_cname)) {
869878
ERR_PRINT("Cannot resolve method reference in documentation: '" + p_link_target + "'.");
870879
}
871880

@@ -908,7 +917,7 @@ void BindingsGenerator::_append_text_member(StringBuilder &p_output, const TypeI
908917
p_output.append(target_iprop->proxy_name);
909918
p_output.append("'");
910919
} else {
911-
if (!p_target_itype->is_intentionally_ignored(p_link_target)) {
920+
if (!p_target_itype->is_intentionally_ignored(p_target_cname)) {
912921
ERR_PRINT("Cannot resolve member reference in documentation: '" + p_link_target + "'.");
913922
}
914923

@@ -939,7 +948,7 @@ void BindingsGenerator::_append_text_signal(StringBuilder &p_output, const TypeI
939948
p_output.append(target_isignal->proxy_name);
940949
p_output.append("'");
941950
} else {
942-
if (!p_target_itype->is_intentionally_ignored(p_link_target)) {
951+
if (!p_target_itype->is_intentionally_ignored(p_target_cname)) {
943952
ERR_PRINT("Cannot resolve signal reference in documentation: '" + p_link_target + "'.");
944953
}
945954

@@ -964,7 +973,7 @@ void BindingsGenerator::_append_text_enum(StringBuilder &p_output, const TypeInt
964973
p_output.append(target_enum_itype.proxy_name); // Includes nesting class if any
965974
p_output.append("'");
966975
} else {
967-
if (p_target_itype == nullptr || !p_target_itype->is_intentionally_ignored(p_link_target)) {
976+
if (p_target_itype == nullptr || !p_target_itype->is_intentionally_ignored(p_target_cname)) {
968977
ERR_PRINT("Cannot resolve enum reference in documentation: '" + p_link_target + "'.");
969978
}
970979

@@ -1032,7 +1041,7 @@ void BindingsGenerator::_append_text_constant(StringBuilder &p_output, const Typ
10321041
// Also search in @GlobalScope as a last resort if no class was specified
10331042
_append_text_constant_in_global_scope(p_output, p_target_cname, p_link_target);
10341043
} else {
1035-
if (!p_target_itype->is_intentionally_ignored(p_link_target)) {
1044+
if (!p_target_itype->is_intentionally_ignored(p_target_cname)) {
10361045
ERR_PRINT("Cannot resolve constant reference in documentation: '" + p_link_target + "'.");
10371046
}
10381047

@@ -1106,12 +1115,15 @@ void BindingsGenerator::_append_xml_method(StringBuilder &p_xml_output, const Ty
11061115
_append_xml_undeclared(p_xml_output, p_link_target);
11071116
} else {
11081117
if (p_target_cname == "_init") {
1109-
// The _init method is not declared in C#, reference the constructor instead
1118+
// The _init method is not declared in C#, reference the constructor instead.
11101119
p_xml_output.append("<see cref=\"" BINDINGS_NAMESPACE ".");
11111120
p_xml_output.append(p_target_itype->proxy_name);
11121121
p_xml_output.append(".");
11131122
p_xml_output.append(p_target_itype->proxy_name);
11141123
p_xml_output.append("()\"/>");
1124+
} else if (p_target_cname == "to_string") {
1125+
// C# uses the built-in object.ToString() method, reference that instead.
1126+
p_xml_output.append("<see cref=\"object.ToString()\"/>");
11151127
} else {
11161128
const MethodInterface *target_imethod = p_target_itype->find_method_by_name(p_target_cname);
11171129

@@ -1149,7 +1161,7 @@ void BindingsGenerator::_append_xml_method(StringBuilder &p_xml_output, const Ty
11491161
p_xml_output.append(")\"/>");
11501162
}
11511163
} else {
1152-
if (!p_target_itype->is_intentionally_ignored(p_link_target)) {
1164+
if (!p_target_itype->is_intentionally_ignored(p_target_cname)) {
11531165
ERR_PRINT("Cannot resolve method reference in documentation: '" + p_link_target + "'.");
11541166
}
11551167

@@ -1195,7 +1207,7 @@ void BindingsGenerator::_append_xml_member(StringBuilder &p_xml_output, const Ty
11951207
p_xml_output.append("\"/>");
11961208
}
11971209
} else {
1198-
if (!p_target_itype->is_intentionally_ignored(p_link_target)) {
1210+
if (!p_target_itype->is_intentionally_ignored(p_target_cname)) {
11991211
ERR_PRINT("Cannot resolve member reference in documentation: '" + p_link_target + "'.");
12001212
}
12011213

@@ -1229,7 +1241,7 @@ void BindingsGenerator::_append_xml_signal(StringBuilder &p_xml_output, const Ty
12291241
p_xml_output.append("\"/>");
12301242
}
12311243
} else {
1232-
if (!p_target_itype->is_intentionally_ignored(p_link_target)) {
1244+
if (!p_target_itype->is_intentionally_ignored(p_target_cname)) {
12331245
ERR_PRINT("Cannot resolve signal reference in documentation: '" + p_link_target + "'.");
12341246
}
12351247

@@ -1258,7 +1270,7 @@ void BindingsGenerator::_append_xml_enum(StringBuilder &p_xml_output, const Type
12581270
p_xml_output.append("\"/>");
12591271
}
12601272
} else {
1261-
if (p_target_itype == nullptr || !p_target_itype->is_intentionally_ignored(p_link_target)) {
1273+
if (p_target_itype == nullptr || !p_target_itype->is_intentionally_ignored(p_target_cname)) {
12621274
ERR_PRINT("Cannot resolve enum reference in documentation: '" + p_link_target + "'.");
12631275
}
12641276

@@ -1326,7 +1338,7 @@ void BindingsGenerator::_append_xml_constant(StringBuilder &p_xml_output, const
13261338
// Also search in @GlobalScope as a last resort if no class was specified
13271339
_append_xml_constant_in_global_scope(p_xml_output, p_target_cname, p_link_target);
13281340
} else {
1329-
if (!p_target_itype->is_intentionally_ignored(p_link_target)) {
1341+
if (!p_target_itype->is_intentionally_ignored(p_target_cname)) {
13301342
ERR_PRINT("Cannot resolve constant reference in documentation: '" + p_link_target + "'.");
13311343
}
13321344

0 commit comments

Comments
 (0)