diff options
Diffstat (limited to 'modules/mono/editor')
| -rw-r--r-- | modules/mono/editor/bindings_generator.cpp | 17 | ||||
| -rw-r--r-- | modules/mono/editor/bindings_generator.h | 23 | ||||
| -rw-r--r-- | modules/mono/editor/godotsharp_builds.cpp | 6 |
3 files changed, 25 insertions, 21 deletions
diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 92eabfc9b2..cd12afb5dd 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -108,6 +108,8 @@ const char *BindingsGenerator::TypeInterface::DEFAULT_VARARG_C_IN = "\t%0 %1_in bool BindingsGenerator::verbose_output = false; +BindingsGenerator *BindingsGenerator::singleton = NULL; + static String snake_to_pascal_case(const String &p_identifier, bool p_input_is_upper = false) { String ret; @@ -200,7 +202,7 @@ void BindingsGenerator::_generate_header_icalls() { core_custom_icalls.clear(); core_custom_icalls.push_back(InternalCall(ICALL_GET_METHODBIND, "IntPtr", "string type, string method")); - core_custom_icalls.push_back(InternalCall(ICALL_OBJECT_DTOR, "void", "IntPtr ptr")); + core_custom_icalls.push_back(InternalCall(ICALL_OBJECT_DTOR, "void", "object obj, IntPtr ptr")); core_custom_icalls.push_back(InternalCall(ICALL_CONNECT_SIGNAL_AWAITER, "Error", "IntPtr source, string signal, IntPtr target, " CS_CLASS_SIGNALAWAITER " awaiter")); @@ -931,8 +933,8 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str "if (" BINDINGS_PTR_FIELD " != IntPtr.Zero)\n" OPEN_BLOCK_L3 "if (" CS_FIELD_MEMORYOWN ")\n" OPEN_BLOCK_L4 CS_FIELD_MEMORYOWN " = false;\n" INDENT5 CS_CLASS_NATIVECALLS "." ICALL_OBJECT_DTOR - "(" BINDINGS_PTR_FIELD ");\n" INDENT5 BINDINGS_PTR_FIELD - " = IntPtr.Zero;\n" CLOSE_BLOCK_L4 CLOSE_BLOCK_L3 INDENT3 + "(this, " BINDINGS_PTR_FIELD ");\n" CLOSE_BLOCK_L4 CLOSE_BLOCK_L3 INDENT3 + "this." BINDINGS_PTR_FIELD " = IntPtr.Zero;\n" INDENT3 "GC.SuppressFinalize(this);\n" INDENT3 "disposed = true;\n" CLOSE_BLOCK_L2); Map<StringName, TypeInterface>::Element *array_itype = builtin_types.find(name_cache.type_Array); @@ -2466,8 +2468,7 @@ void BindingsGenerator::_populate_global_constants() { } } -BindingsGenerator::BindingsGenerator() : - name_cache(NameCache::get_singleton()) { +void BindingsGenerator::initialize() { EditorHelp::generate_doc(); @@ -2509,7 +2510,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) const List<String>::Element *path_elem = elem->next(); if (path_elem) { - if (get_singleton().generate_glue(path_elem->get()) != OK) + if (get_singleton()->generate_glue(path_elem->get()) != OK) ERR_PRINT("Mono glue generation failed"); elem = elem->next(); } else { @@ -2523,7 +2524,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) const List<String>::Element *path_elem = elem->next(); if (path_elem) { - if (get_singleton().generate_cs_core_project(path_elem->get()) != OK) + if (get_singleton()->generate_cs_core_project(path_elem->get()) != OK) ERR_PRINT("Generation of solution and C# project for the Core API failed"); elem = elem->next(); } else { @@ -2538,7 +2539,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) if (path_elem) { if (path_elem->next()) { - if (get_singleton().generate_cs_editor_project(path_elem->get(), path_elem->next()->get()) != OK) + if (get_singleton()->generate_cs_editor_project(path_elem->get(), path_elem->next()->get()) != OK) ERR_PRINT("Generation of solution and C# project for the Editor API failed"); elem = path_elem->next(); } else { diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h index eac00690ff..5934f3f27f 100644 --- a/modules/mono/editor/bindings_generator.h +++ b/modules/mono/editor/bindings_generator.h @@ -145,7 +145,7 @@ class BindingsGenerator { } MethodInterface() { - return_type = NameCache::get_singleton().type_void; + return_type = BindingsGenerator::get_singleton()->name_cache.type_void; is_vararg = false; is_virtual = false; requires_object_call = false; @@ -469,16 +469,11 @@ class BindingsGenerator { enum_Error = StaticCString::create("Error"); } - static NameCache &get_singleton() { - static NameCache singleton; - return singleton; - } - NameCache(const NameCache &); NameCache &operator=(const NameCache &); }; - const NameCache &name_cache; + NameCache name_cache; const List<InternalCall>::Element *find_icall_by_name(const String &p_name, const List<InternalCall> &p_list) { const List<InternalCall>::Element *it = p_list.front(); @@ -525,18 +520,26 @@ class BindingsGenerator { Error _save_file(const String &path, const List<String> &content); - BindingsGenerator(); + BindingsGenerator() {} BindingsGenerator(const BindingsGenerator &); BindingsGenerator &operator=(const BindingsGenerator &); + friend class CSharpLanguage; + static BindingsGenerator *singleton; + public: Error generate_cs_core_project(const String &p_output_dir, bool p_verbose_output = true); Error generate_cs_editor_project(const String &p_output_dir, const String &p_core_dll_path, bool p_verbose_output = true); Error generate_glue(const String &p_output_dir); - static BindingsGenerator &get_singleton() { - static BindingsGenerator singleton; + void initialize(); + + _FORCE_INLINE_ static BindingsGenerator *get_singleton() { + if (!singleton) { + singleton = memnew(BindingsGenerator); + singleton->initialize(); + } return singleton; } diff --git a/modules/mono/editor/godotsharp_builds.cpp b/modules/mono/editor/godotsharp_builds.cpp index 3750a2b02a..3c06537816 100644 --- a/modules/mono/editor/godotsharp_builds.cpp +++ b/modules/mono/editor/godotsharp_builds.cpp @@ -238,12 +238,12 @@ bool GodotSharpBuilds::make_api_sln(GodotSharpBuilds::APIType p_api_type) { #error "How am I supposed to generate the bindings?" #endif - BindingsGenerator &gen = BindingsGenerator::get_singleton(); + BindingsGenerator *gen = BindingsGenerator::get_singleton(); bool gen_verbose = OS::get_singleton()->is_stdout_verbose(); Error err = p_api_type == API_CORE ? - gen.generate_cs_core_project(api_sln_dir, gen_verbose) : - gen.generate_cs_editor_project(api_sln_dir, core_api_assembly, gen_verbose); + gen->generate_cs_core_project(api_sln_dir, gen_verbose) : + gen->generate_cs_editor_project(api_sln_dir, core_api_assembly, gen_verbose); if (err != OK) { show_build_error_dialog("Failed to generate " + api_name + " solution. Error: " + itos(err)); |