summaryrefslogtreecommitdiffstats
path: root/modules/mono/editor/bindings_generator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono/editor/bindings_generator.cpp')
-rw-r--r--modules/mono/editor/bindings_generator.cpp67
1 files changed, 35 insertions, 32 deletions
diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp
index 7960a1ad5b..0a9162bd28 100644
--- a/modules/mono/editor/bindings_generator.cpp
+++ b/modules/mono/editor/bindings_generator.cpp
@@ -1538,7 +1538,7 @@ void BindingsGenerator::_generate_global_constants(StringBuilder &p_output) {
p_output.append("namespace " BINDINGS_NAMESPACE ";\n\n");
- p_output.append("public static partial class " BINDINGS_GLOBAL_SCOPE_CLASS "\n{");
+ p_output.append("public static partial class " BINDINGS_GLOBAL_SCOPE_CLASS "\n" OPEN_BLOCK);
for (const ConstantInterface &iconstant : global_constants) {
if (iconstant.const_doc && iconstant.const_doc->description.size()) {
@@ -1589,50 +1589,48 @@ void BindingsGenerator::_generate_global_constants(StringBuilder &p_output) {
_log("Declaring global enum '%s' inside struct '%s'\n", enum_proxy_name.utf8().get_data(), enum_class_name.utf8().get_data());
- p_output.append("\npublic partial struct ");
- p_output.append(enum_class_name);
- p_output.append("\n" OPEN_BLOCK);
+ p_output << "\npublic partial struct " << enum_class_name << "\n" OPEN_BLOCK;
}
+ const String maybe_indent = !enum_in_static_class ? "" : INDENT1;
+
if (ienum.is_flags) {
- p_output.append("\n[System.Flags]");
+ p_output << "\n"
+ << maybe_indent << "[System.Flags]";
}
- p_output.append("\npublic enum ");
- p_output.append(enum_proxy_name);
- p_output.append(" : long");
- p_output.append("\n" OPEN_BLOCK);
+ p_output << "\n"
+ << maybe_indent << "public enum " << enum_proxy_name << " : long"
+ << "\n"
+ << maybe_indent << OPEN_BLOCK;
- const ConstantInterface &last = ienum.constants.back()->get();
for (const ConstantInterface &iconstant : ienum.constants) {
if (iconstant.const_doc && iconstant.const_doc->description.size()) {
String xml_summary = bbcode_to_xml(fix_doc_description(iconstant.const_doc->description), nullptr);
Vector<String> summary_lines = xml_summary.length() ? xml_summary.split("\n") : Vector<String>();
if (summary_lines.size()) {
- p_output.append(INDENT1 "/// <summary>\n");
+ p_output << maybe_indent << INDENT1 "/// <summary>\n";
for (int i = 0; i < summary_lines.size(); i++) {
- p_output.append(INDENT1 "/// ");
- p_output.append(summary_lines[i]);
- p_output.append("\n");
+ p_output << maybe_indent << INDENT1 "/// " << summary_lines[i] << "\n";
}
- p_output.append(INDENT1 "/// </summary>\n");
+ p_output << maybe_indent << INDENT1 "/// </summary>\n";
}
}
- p_output.append(INDENT1);
- p_output.append(iconstant.proxy_name);
- p_output.append(" = ");
- p_output.append(itos(iconstant.value));
- p_output.append(&iconstant != &last ? ",\n" : "\n");
+ p_output << maybe_indent << INDENT1
+ << iconstant.proxy_name
+ << " = "
+ << itos(iconstant.value)
+ << ",\n";
}
- p_output.append(CLOSE_BLOCK);
+ p_output << maybe_indent << CLOSE_BLOCK;
if (enum_in_static_class) {
- p_output.append(CLOSE_BLOCK);
+ p_output << CLOSE_BLOCK;
}
}
}
@@ -2162,7 +2160,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
output << MEMBER_BEGIN "public " << itype.proxy_name << "() : this("
<< (itype.memory_own ? "true" : "false") << ")\n" OPEN_BLOCK_L1
<< INDENT2 "unsafe\n" INDENT2 OPEN_BLOCK
- << INDENT3 "_ConstructAndInitialize(" CS_STATIC_FIELD_NATIVE_CTOR ", "
+ << INDENT3 "ConstructAndInitialize(" CS_STATIC_FIELD_NATIVE_CTOR ", "
<< BINDINGS_NATIVE_NAME_FIELD ", CachedType, refCounted: "
<< (itype.is_ref_counted ? "true" : "false") << ");\n"
<< CLOSE_BLOCK_L2 CLOSE_BLOCK_L1;
@@ -2171,7 +2169,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
output << MEMBER_BEGIN "internal " << itype.proxy_name << "() : this("
<< (itype.memory_own ? "true" : "false") << ")\n" OPEN_BLOCK_L1
<< INDENT2 "unsafe\n" INDENT2 OPEN_BLOCK
- << INDENT3 "_ConstructAndInitialize(null, "
+ << INDENT3 "ConstructAndInitialize(null, "
<< BINDINGS_NATIVE_NAME_FIELD ", CachedType, refCounted: "
<< (itype.is_ref_counted ? "true" : "false") << ");\n"
<< CLOSE_BLOCK_L2 CLOSE_BLOCK_L1;
@@ -2180,7 +2178,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
// Add.. em.. trick constructor. Sort of.
output.append(MEMBER_BEGIN "internal ");
output.append(itype.proxy_name);
- output.append("(bool " CS_PARAM_MEMORYOWN ") : base(" CS_PARAM_MEMORYOWN ") {}\n");
+ output.append("(bool " CS_PARAM_MEMORYOWN ") : base(" CS_PARAM_MEMORYOWN ") { }\n");
}
}
@@ -2241,6 +2239,9 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
<< INDENT1 "/// <param name=\"args\">Arguments to use with the invoked method.</param>\n"
<< INDENT1 "/// <param name=\"ret\">Value returned by the invoked method.</param>\n";
+ // Avoid raising diagnostics because of calls to obsolete methods.
+ output << "#pragma warning disable CS0618 // Member is obsolete\n";
+
output << INDENT1 "protected internal " << (is_derived_type ? "override" : "virtual")
<< " bool " CS_METHOD_INVOKE_GODOT_CLASS_METHOD "(in godot_string_name method, "
<< "NativeVariantPtrArgs args, out godot_variant ret)\n"
@@ -2319,6 +2320,8 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
output << INDENT1 "}\n";
+ output << "#pragma warning restore CS0618\n";
+
// Generate HasGodotClassMethod
output << MEMBER_BEGIN "/// <summary>\n"
@@ -2969,7 +2972,7 @@ Error BindingsGenerator::_generate_cs_signal(const BindingsGenerator::TypeInterf
ERR_FAIL_NULL_V(arg_type, ERR_BUG); // Argument type not found
if (idx != 0) {
- p_output << ",";
+ p_output << ", ";
}
p_output << sformat(arg_type->cs_variant_to_managed,
@@ -3568,7 +3571,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
itype.is_deprecated = itype.class_doc->is_deprecated;
itype.deprecation_message = itype.class_doc->deprecated_message;
- if (itype.deprecation_message.is_empty()) {
+ if (itype.is_deprecated && itype.deprecation_message.is_empty()) {
WARN_PRINT("An empty deprecation message is discouraged. Type: '" + itype.proxy_name + "'.");
itype.deprecation_message = "This class is deprecated.";
}
@@ -3652,7 +3655,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
iprop.is_deprecated = iprop.prop_doc->is_deprecated;
iprop.deprecation_message = iprop.prop_doc->deprecated_message;
- if (iprop.deprecation_message.is_empty()) {
+ if (iprop.is_deprecated && iprop.deprecation_message.is_empty()) {
WARN_PRINT("An empty deprecation message is discouraged. Property: '" + itype.proxy_name + "." + iprop.proxy_name + "'.");
iprop.deprecation_message = "This property is deprecated.";
}
@@ -3841,7 +3844,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
imethod.is_deprecated = imethod.method_doc->is_deprecated;
imethod.deprecation_message = imethod.method_doc->deprecated_message;
- if (imethod.deprecation_message.is_empty()) {
+ if (imethod.is_deprecated && imethod.deprecation_message.is_empty()) {
WARN_PRINT("An empty deprecation message is discouraged. Method: '" + itype.proxy_name + "." + imethod.proxy_name + "'.");
imethod.deprecation_message = "This method is deprecated.";
}
@@ -3957,7 +3960,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
isignal.is_deprecated = isignal.method_doc->is_deprecated;
isignal.deprecation_message = isignal.method_doc->deprecated_message;
- if (isignal.deprecation_message.is_empty()) {
+ if (isignal.is_deprecated && isignal.deprecation_message.is_empty()) {
WARN_PRINT("An empty deprecation message is discouraged. Signal: '" + itype.proxy_name + "." + isignal.proxy_name + "'.");
isignal.deprecation_message = "This signal is deprecated.";
}
@@ -4007,7 +4010,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
iconstant.is_deprecated = iconstant.const_doc->is_deprecated;
iconstant.deprecation_message = iconstant.const_doc->deprecated_message;
- if (iconstant.deprecation_message.is_empty()) {
+ if (iconstant.is_deprecated && iconstant.deprecation_message.is_empty()) {
WARN_PRINT("An empty deprecation message is discouraged. Enum member: '" + itype.proxy_name + "." + ienum.proxy_name + "." + iconstant.proxy_name + "'.");
iconstant.deprecation_message = "This enum member is deprecated.";
}
@@ -4059,7 +4062,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
iconstant.is_deprecated = iconstant.const_doc->is_deprecated;
iconstant.deprecation_message = iconstant.const_doc->deprecated_message;
- if (iconstant.deprecation_message.is_empty()) {
+ if (iconstant.is_deprecated && iconstant.deprecation_message.is_empty()) {
WARN_PRINT("An empty deprecation message is discouraged. Constant: '" + itype.proxy_name + "." + iconstant.proxy_name + "'.");
iconstant.deprecation_message = "This constant is deprecated.";
}