static/source/embindmaker/embindmaker.cxx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
New commits: commit 7938c1e88d02aa2b26e84cfeb5c99ebc77e50215 Author: Stephan Bergmann <[email protected]> AuthorDate: Wed Jan 31 10:31:36 2024 +0100 Commit: Stephan Bergmann <[email protected]> CommitDate: Wed Jan 31 12:20:45 2024 +0100 embindmaker: Handle new-style singletons Change-Id: Icb3b179c95e1af8b12772401f58d4f4cf181e585 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162795 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx index cb0ad6c04445..498e5ff0e551 100644 --- a/static/source/embindmaker/embindmaker.cxx +++ b/static/source/embindmaker/embindmaker.cxx @@ -136,8 +136,11 @@ jsServiceConstructor(OUString const& service, return "uno_Function_" + jsName(service) + "$$" + getServiceConstructorName(constructor); } +OUString jsSingleton(OUString const& singleton) { return "uno_Function_" + jsName(singleton); } + void scan(rtl::Reference<unoidl::MapCursor> const& cursor, std::u16string_view prefix, - Module* module, std::vector<OUString>& interfaces, std::vector<OUString>& services) + Module* module, std::vector<OUString>& interfaces, std::vector<OUString>& services, + std::vector<OUString>& singletons) { assert(cursor.is()); assert(module != nullptr); @@ -160,7 +163,7 @@ void scan(rtl::Reference<unoidl::MapCursor> const& cursor, std::u16string_view p sub = std::make_shared<Module>(); } scan(static_cast<unoidl::ModuleEntity*>(ent.get())->createCursor(), - Concat2View(name + "."), sub.get(), interfaces, services); + Concat2View(name + "."), sub.get(), interfaces, services, singletons); break; } case unoidl::Entity::SORT_INTERFACE_TYPE: @@ -185,6 +188,10 @@ void scan(rtl::Reference<unoidl::MapCursor> const& cursor, std::u16string_view p } } break; + case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON: + module->mappings.emplace_back(id, jsSingleton(name)); + singletons.emplace_back(name); + break; default: break; } @@ -685,9 +692,10 @@ SAL_IMPLEMENT_MAIN() auto const module = std::make_shared<Module>(); std::vector<OUString> interfaces; std::vector<OUString> services; + std::vector<OUString> singletons; for (auto const& prov : mgr->getPrimaryProviders()) { - scan(prov->createRootCursor(), u"", module.get(), interfaces, services); + scan(prov->createRootCursor(), u"", module.get(), interfaces, services, singletons); } std::ofstream cppOut(cppPathname, std::ios_base::out | std::ios_base::trunc); if (!cppOut) @@ -707,6 +715,10 @@ SAL_IMPLEMENT_MAIN() { cppOut << "#include <" << srv.replace('.', '/') << ".hpp> "; } + for (auto const& sng : singletons) + { + cppOut << "#include <" << sng.replace('.', '/') << ".hpp> "; + } cppOut << " " "// TODO: This is a temporary workaround that likely causes the Embind UNO " "// bindings to leak memory. Reference counting and cloning mechanisms of " @@ -788,6 +800,13 @@ SAL_IMPLEMENT_MAIN() } dumpRegisterFunctionEpilog(cppOut, n); } + for (auto const& sng : singletons) + { + dumpRegisterFunctionProlog(cppOut, n); + cppOut << " ::emscripten::function(\"" << jsSingleton(sng) << "\", &" << cppName(sng) + << "::get); "; + dumpRegisterFunctionEpilog(cppOut, n); + } cppOut << "EMSCRIPTEN_BINDINGS(unoembind_" << name << ") { "; for (unsigned long long i = 0; i != n; ++i) {
