diff options
author | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-01-31 17:31:49 +0100 |
---|---|---|
committer | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-02-01 08:46:47 +0100 |
commit | 8869994d5e62c422465f52b25dc3792be9add92d (patch) | |
tree | 76a3f02d1d48c0be2f82763b283406dc4658d8cd /static/source/embindmaker/embindmaker.cxx | |
parent | 40045883b04e1c0694f802d98d417c9b48e0f4fd (diff) |
embindmaker: Add support for sequence types
Ideally, JS code would have a way to create instances of arbitrary UNO sequence
types (to e.g. put them into Anys), but that goes against the static nature of
Embind. So at least register JS support for all those UNO sequence types that
are actually used in the UNO API. (This would cause duplicate failures, though,
if we generated multiple separate .cxx files from embindmaker invocations, with
registration code for the same UNO sequence types.)
(Even more ideally, UNO sequence types could map to JS arrays, and/oror be
garbage-collected on the JS side rather than needing explicit delete(). The
resize/size/get/set interface in unoembindhelpers::registerSequence is modelled
after Embind's emscripten::register_vector.)
Change-Id: Icd38b2e03db442dd613b9222b9bd092f947f7bec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162849
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static/source/embindmaker/embindmaker.cxx')
-rw-r--r-- | static/source/embindmaker/embindmaker.cxx | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx index 43d315679d6c..fb6ba0880508 100644 --- a/static/source/embindmaker/embindmaker.cxx +++ b/static/source/embindmaker/embindmaker.cxx @@ -725,6 +725,16 @@ void dumpRegisterFunctionEpilog(std::ostream& out, unsigned long long& counter) } } +void recordSequenceTypes(rtl::Reference<TypeManager> const& manager, OUString const& type, + std::set<OUString>& sequences) +{ + auto const res = resolveAllTypedefs(manager, type); + if (manager->getSort(res) == codemaker::UnoType::Sort::Sequence) + { + sequences.insert(res); + } +} + void writeJsMap(std::ostream& out, Module const& module, std::string const& prefix) { auto comma = false; @@ -852,6 +862,7 @@ SAL_IMPLEMENT_MAIN() cppOut << ";\n"; dumpRegisterFunctionEpilog(cppOut, n); } + std::set<OUString> sequences; for (auto const& str : structs) { auto const ent = mgr->getManager()->findEntity(str); @@ -878,6 +889,10 @@ SAL_IMPLEMENT_MAIN() } cppOut << ";\n"; dumpRegisterFunctionEpilog(cppOut, n); + for (auto const& mem : strEnt->getDirectMembers()) + { + recordSequenceTypes(mgr, mem.type, sequences); + } } for (auto const& ifc : interfaces) { @@ -931,6 +946,18 @@ SAL_IMPLEMENT_MAIN() dumpMethods(cppOut, mgr, ifc, ifcEnt, {}); cppOut << " ;\n"; dumpRegisterFunctionEpilog(cppOut, n); + for (auto const& attr : ifcEnt->getDirectAttributes()) + { + recordSequenceTypes(mgr, attr.type, sequences); + } + for (auto const& meth : ifcEnt->getDirectMethods()) + { + for (auto const& param : meth.parameters) + { + recordSequenceTypes(mgr, param.type, sequences); + } + recordSequenceTypes(mgr, meth.returnType, sequences); + } } for (auto const& srv : services) { @@ -960,6 +987,21 @@ SAL_IMPLEMENT_MAIN() { cppOut << " register" << i << "();\n"; } + for (auto const& seq : sequences) + { + cppOut << " ::unoembindhelpers::registerSequence<"; + assert(seq.startsWith("[]")); + dumpType(cppOut, mgr, seq.copy(2)); + cppOut << ">(\"uno_Sequence"; + sal_Int32 k; + auto const nuc = b2u(codemaker::UnoType::decompose(u2b(seq), &k)); + assert(k >= 1); + if (k > 1) + { + cppOut << k; + } + cppOut << "_" << jsName(nuc) << "\");\n"; + } cppOut << "}\n"; cppOut.close(); if (!cppOut) |