summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-02-07 17:23:58 +0100
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-02-08 08:36:06 +0100
commit578d9be50413a4bdc809f8b5f58cc177458f8325 (patch)
tree26f31cbc95dbb788ec4634b73887eb08cac042d6 /static
parentcf616121ed48c8df96104bc35abf3b55b8862043 (diff)
Embind: Map UNO structs to emscripten::value_object
...so that it has a nicer integration into JS, at the expense of copying data between C++ and JS Change-Id: I19af55e8db0c374dd7b0f58f74d1af19214175b4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163098 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r--static/source/embindmaker/embindmaker.cxx86
1 files changed, 5 insertions, 81 deletions
diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx
index fb6ba0880508..bff11e99b16d 100644
--- a/static/source/embindmaker/embindmaker.cxx
+++ b/static/source/embindmaker/embindmaker.cxx
@@ -378,61 +378,6 @@ void dumpType(std::ostream& out, rtl::Reference<TypeManager> const& manager,
}
}
-bool hasStructMembers(rtl::Reference<TypeManager> const& manager,
- rtl::Reference<unoidl::PlainStructTypeEntity> struc)
-{
- for (;;)
- {
- if (!struc->getDirectMembers().empty())
- {
- return true;
- }
- auto const& base = struc->getDirectBase();
- if (base.isEmpty())
- {
- return false;
- }
- auto const ent = manager->getManager()->findEntity(base);
- if (!ent.is() || ent->getSort() != unoidl::Entity::SORT_PLAIN_STRUCT_TYPE)
- {
- throw CannotDumpException("bad struct base \"" + base + "\"");
- }
- struc = static_cast<unoidl::PlainStructTypeEntity*>(ent.get());
- }
-}
-
-void dumpStructMemberTypes(std::ostream& out, rtl::Reference<TypeManager> const& manager,
- rtl::Reference<unoidl::PlainStructTypeEntity> struc, bool& first)
-{
- auto const& base = struc->getDirectBase();
- if (!base.isEmpty())
- {
- auto const ent = manager->getManager()->findEntity(base);
- if (!ent.is() || ent->getSort() != unoidl::Entity::SORT_PLAIN_STRUCT_TYPE)
- {
- throw CannotDumpException("bad struct base \"" + base + "\"");
- }
- dumpStructMemberTypes(out, manager, static_cast<unoidl::PlainStructTypeEntity*>(ent.get()),
- first);
- }
- for (auto const& mem : struc->getDirectMembers())
- {
- if (first)
- {
- first = false;
- }
- else
- {
- out << ", ";
- }
- dumpType(out, manager, mem.type);
- if (passByReference(manager, mem.type))
- {
- out << " const &";
- }
- }
-}
-
void dumpStructMembers(std::ostream& out, rtl::Reference<TypeManager> const& manager,
OUString const& name, rtl::Reference<unoidl::PlainStructTypeEntity> struc)
{
@@ -449,15 +394,8 @@ void dumpStructMembers(std::ostream& out, rtl::Reference<TypeManager> const& man
}
for (auto const& mem : struc->getDirectMembers())
{
- out << "\n .property(\"" << mem.name << "\", +[](" << cppName(name)
- << " const & the_self) { return the_self." << mem.name << "; }, +[](" << cppName(name)
- << " & the_self, ";
- dumpType(out, manager, mem.type);
- if (passByReference(manager, mem.type))
- {
- out << " const &";
- }
- out << " the_value) { the_self." << mem.name << " = the_value; })";
+ out << "\n .field(\"" << mem.name << "\", &" << cppName(name) << "::" << mem.name
+ << ")";
}
}
@@ -870,23 +808,9 @@ SAL_IMPLEMENT_MAIN()
assert(ent->getSort() == unoidl::Entity::SORT_PLAIN_STRUCT_TYPE);
rtl::Reference const strEnt(static_cast<unoidl::PlainStructTypeEntity*>(ent.get()));
dumpRegisterFunctionProlog(cppOut, n);
- cppOut << " ::emscripten::class_<" << cppName(str);
- auto const& base = strEnt->getDirectBase();
- if (!base.isEmpty())
- {
- cppOut << ", ::emscripten::base<" << cppName(base) << ">";
- }
- cppOut << ">(\"uno_Type_" << jsName(str)
- << "\")\n"
- " .constructor()";
- if (hasStructMembers(mgr, strEnt))
- {
- cppOut << "\n .constructor<";
- auto first = true;
- dumpStructMemberTypes(cppOut, mgr, strEnt, first);
- cppOut << ">()";
- dumpStructMembers(cppOut, mgr, str, strEnt);
- }
+ cppOut << " ::emscripten::value_object<" << cppName(str) << ">(\"uno_Type_"
+ << jsName(str) << "\")";
+ dumpStructMembers(cppOut, mgr, str, strEnt);
cppOut << ";\n";
dumpRegisterFunctionEpilog(cppOut, n);
for (auto const& mem : strEnt->getDirectMembers())