From 2511c439727226f64def8b15b38d084db187cf55 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Sun, 5 Jul 2020 19:19:36 +0200 Subject: [PATCH] Mono/C#: Fix several clang-tidy warnings and cleanup --- modules/mono/class_db_api_json.cpp | 6 +- modules/mono/csharp_script.cpp | 313 ++++++++++++------ modules/mono/csharp_script.h | 253 +++++++------- modules/mono/editor/bindings_generator.cpp | 2 - modules/mono/editor/code_completion.cpp | 18 +- modules/mono/editor/csharp_project.cpp | 3 +- modules/mono/editor/editor_internal_calls.cpp | 2 +- modules/mono/editor/godotsharp_export.cpp | 6 +- modules/mono/editor/script_class_parser.cpp | 51 ++- modules/mono/editor/script_class_parser.h | 1 - modules/mono/glue/arguments_vector.h | 4 +- modules/mono/glue/base_object_glue.cpp | 12 +- modules/mono/glue/base_object_glue.h | 73 ---- modules/mono/glue/collections_glue.cpp | 5 +- modules/mono/glue/collections_glue.h | 124 ------- modules/mono/glue/gd_glue.cpp | 16 +- modules/mono/glue/gd_glue.h | 86 ----- modules/mono/glue/glue_header.h | 18 +- modules/mono/glue/nodepath_glue.cpp | 9 +- modules/mono/glue/nodepath_glue.h | 68 ---- modules/mono/glue/rid_glue.cpp | 9 +- modules/mono/glue/rid_glue.h | 53 --- modules/mono/glue/scene_tree_glue.cpp | 14 +- modules/mono/glue/scene_tree_glue.h | 50 --- modules/mono/glue/string_glue.cpp | 4 +- modules/mono/glue/string_glue.h | 56 ---- modules/mono/glue/string_name_glue.cpp | 7 +- modules/mono/glue/string_name_glue.h | 54 --- modules/mono/managed_callable.cpp | 6 +- modules/mono/mono_gd/gd_mono.cpp | 151 ++++++--- modules/mono/mono_gd/gd_mono.h | 27 +- modules/mono/mono_gd/gd_mono_assembly.cpp | 63 ++-- modules/mono/mono_gd/gd_mono_cache.cpp | 2 +- modules/mono/mono_gd/gd_mono_class.cpp | 69 ++-- modules/mono/mono_gd/gd_mono_field.cpp | 12 +- modules/mono/mono_gd/gd_mono_internals.cpp | 5 +- modules/mono/mono_gd/gd_mono_log.cpp | 9 +- modules/mono/mono_gd/gd_mono_marshal.cpp | 309 ++++++++++------- modules/mono/mono_gd/gd_mono_marshal.h | 10 +- modules/mono/mono_gd/gd_mono_method.cpp | 18 +- modules/mono/mono_gd/gd_mono_property.cpp | 18 +- modules/mono/mono_gd/gd_mono_utils.cpp | 35 +- modules/mono/mono_gd/gd_mono_utils.h | 5 - modules/mono/register_types.cpp | 6 +- modules/mono/signal_awaiter_utils.cpp | 18 +- modules/mono/utils/path_utils.cpp | 46 +-- modules/mono/utils/path_utils.h | 2 - modules/mono/utils/string_utils.cpp | 12 +- 48 files changed, 935 insertions(+), 1205 deletions(-) delete mode 100644 modules/mono/glue/base_object_glue.h delete mode 100644 modules/mono/glue/collections_glue.h delete mode 100644 modules/mono/glue/gd_glue.h delete mode 100644 modules/mono/glue/nodepath_glue.h delete mode 100644 modules/mono/glue/rid_glue.h delete mode 100644 modules/mono/glue/scene_tree_glue.h delete mode 100644 modules/mono/glue/string_glue.h delete mode 100644 modules/mono/glue/string_name_glue.h diff --git a/modules/mono/class_db_api_json.cpp b/modules/mono/class_db_api_json.cpp index 39e3a95afa3..d7b20282041 100644 --- a/modules/mono/class_db_api_json.cpp +++ b/modules/mono/class_db_api_json.cpp @@ -53,8 +53,9 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { for (List::Element *E = names.front(); E; E = E->next()) { ClassDB::ClassInfo *t = ClassDB::classes.getptr(E->get()); ERR_FAIL_COND(!t); - if (t->api != p_api || !t->exposed) + if (t->api != p_api || !t->exposed) { continue; + } Dictionary class_dict; classes_dict[t->name] = class_dict; @@ -72,8 +73,9 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { ERR_CONTINUE(name.empty()); - if (name[0] == '_') + if (name[0] == '_') { continue; // Ignore non-virtual methods that start with an underscore + } snames.push_back(*k); } diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index ae25bd3544e..22e4d84e981 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -125,8 +125,9 @@ void CSharpLanguage::init() { print_line("Run this binary with '--generate-mono-glue path/to/modules/mono/glue'"); #endif - if (gdmono->is_runtime_initialized()) + if (gdmono->is_runtime_initialized()) { gdmono->initialize_load_assemblies(); + } #ifdef TOOLS_ENABLED EditorNode::add_init_callback(&_editor_init_callback); @@ -134,8 +135,13 @@ void CSharpLanguage::init() { } void CSharpLanguage::finish() { - if (finalized) + finalize(); +} + +void CSharpLanguage::finalize() { + if (finalized) { return; + } finalizing = true; @@ -390,15 +396,17 @@ bool CSharpLanguage::supports_builtin_mode() const { #ifdef TOOLS_ENABLED static String variant_type_to_managed_name(const String &p_var_type_name) { - if (p_var_type_name.empty()) + if (p_var_type_name.empty()) { return "object"; + } if (!ClassDB::class_exists(p_var_type_name)) { return p_var_type_name; } - if (p_var_type_name == Variant::get_type_name(Variant::OBJECT)) + if (p_var_type_name == Variant::get_type_name(Variant::OBJECT)) { return "Godot.Object"; + } if (p_var_type_name == Variant::get_type_name(Variant::FLOAT)) { #ifdef REAL_T_IS_DOUBLE @@ -408,36 +416,49 @@ static String variant_type_to_managed_name(const String &p_var_type_name) { #endif } - if (p_var_type_name == Variant::get_type_name(Variant::STRING)) + if (p_var_type_name == Variant::get_type_name(Variant::STRING)) { return "string"; // I prefer this one >:[ + } - if (p_var_type_name == Variant::get_type_name(Variant::DICTIONARY)) + if (p_var_type_name == Variant::get_type_name(Variant::DICTIONARY)) { return "Collections.Dictionary"; + } - if (p_var_type_name == Variant::get_type_name(Variant::ARRAY)) + if (p_var_type_name == Variant::get_type_name(Variant::ARRAY)) { return "Collections.Array"; + } - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_BYTE_ARRAY)) + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_BYTE_ARRAY)) { return "byte[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT32_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT32_ARRAY)) { return "int[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT64_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT64_ARRAY)) { return "long[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_FLOAT32_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_FLOAT32_ARRAY)) { return "float[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_FLOAT64_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_FLOAT64_ARRAY)) { return "double[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_STRING_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_STRING_ARRAY)) { return "string[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_VECTOR2_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_VECTOR2_ARRAY)) { return "Vector2[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_VECTOR3_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_VECTOR3_ARRAY)) { return "Vector3[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_COLOR_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_COLOR_ARRAY)) { return "Color[]"; + } - if (p_var_type_name == Variant::get_type_name(Variant::SIGNAL)) + if (p_var_type_name == Variant::get_type_name(Variant::SIGNAL)) { return "SignalInfo"; + } Variant::Type var_types[] = { Variant::BOOL, @@ -462,8 +483,9 @@ static String variant_type_to_managed_name(const String &p_var_type_name) { }; for (unsigned int i = 0; i < sizeof(var_types) / sizeof(Variant::Type); i++) { - if (p_var_type_name == Variant::get_type_name(var_types[i])) + if (p_var_type_name == Variant::get_type_name(var_types[i])) { return p_var_type_name; + } } return "object"; @@ -477,8 +499,9 @@ String CSharpLanguage::make_function(const String &, const String &p_name, const for (int i = 0; i < p_args.size(); i++) { const String &arg = p_args[i]; - if (i > 0) + if (i > 0) { s += ", "; + } s += variant_type_to_managed_name(arg.get_slice(":", 1)) + " " + escape_csharp_keyword(arg.get_slice(":", 0)); } @@ -516,32 +539,36 @@ String CSharpLanguage::debug_get_error() const { } int CSharpLanguage::debug_get_stack_level_count() const { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return 1; + } // TODO: StackTrace return 1; } int CSharpLanguage::debug_get_stack_level_line(int p_level) const { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return _debug_parse_err_line; + } // TODO: StackTrace return 1; } String CSharpLanguage::debug_get_stack_level_function(int p_level) const { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return String(); + } // TODO: StackTrace return String(); } String CSharpLanguage::debug_get_stack_level_source(int p_level) const { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return _debug_parse_err_file; + } // TODO: StackTrace return String(); @@ -551,15 +578,17 @@ Vector CSharpLanguage::debug_get_current_stack_info() #ifdef DEBUG_ENABLED // Printing an error here will result in endless recursion, so we must be careful static thread_local bool _recursion_flag_ = false; - if (_recursion_flag_) + if (_recursion_flag_) { return Vector(); + } _recursion_flag_ = true; SCOPE_EXIT { _recursion_flag_ = false; }; GD_MONO_SCOPE_THREAD_ATTACH; - if (!gdmono->is_runtime_initialized() || !GDMono::get_singleton()->get_core_api_assembly() || !GDMonoCache::cached_data.corlib_cache_updated) + if (!gdmono->is_runtime_initialized() || !GDMono::get_singleton()->get_core_api_assembly() || !GDMonoCache::cached_data.corlib_cache_updated) { return Vector(); + } MonoObject *stack_trace = mono_object_new(mono_domain_get(), CACHED_CLASS(System_Diagnostics_StackTrace)->get_mono_ptr()); @@ -581,8 +610,9 @@ Vector CSharpLanguage::debug_get_current_stack_info() Vector CSharpLanguage::stack_trace_get_info(MonoObject *p_stack_trace) { // Printing an error here will result in endless recursion, so we must be careful static thread_local bool _recursion_flag_ = false; - if (_recursion_flag_) + if (_recursion_flag_) { return Vector(); + } _recursion_flag_ = true; SCOPE_EXIT { _recursion_flag_ = false; }; @@ -599,8 +629,9 @@ Vector CSharpLanguage::stack_trace_get_info(MonoObjec int frame_count = mono_array_length(frames); - if (frame_count <= 0) + if (frame_count <= 0) { return Vector(); + } Vector si; si.resize(frame_count); @@ -646,8 +677,9 @@ void CSharpLanguage::pre_unsafe_unreference(Object *p_obj) { ObjectID id = p_obj->get_instance_id(); Map::Element *elem = unsafe_object_references.find(id); ERR_FAIL_NULL(elem); - if (--elem->value() == 0) + if (--elem->value() == 0) { unsafe_object_references.erase(elem); + } #endif } @@ -673,8 +705,9 @@ void CSharpLanguage::frame() { struct CSharpScriptDepSort { // must support sorting so inheritance works properly (parent must be reloaded first) bool operator()(const Ref &A, const Ref &B) const { - if (A == B) + if (A == B) { return false; // shouldn't happen but.. + } GDMonoClass *I = B->base; while (I) { if (I == A->script_class) { @@ -717,8 +750,9 @@ void CSharpLanguage::reload_tool_script(const Ref