summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-03-05 16:37:01 +0100
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-03-06 00:02:36 +0100
commit567a10caef0f2ebc9390babda545b410b5aa36c6 (patch)
tree352e47e22447989710c65909550a8be2c5475c21 /static
parent792a2847c8d9b6618fa920aaee1a6289248fca87 (diff)
Add Embind'ing of UNO Any getter for exceptions
Change-Id: Ief3cdebc1ee7c7b9f012741c9db8637dba9bbd07 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164433 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r--static/source/embindmaker/embindmaker.cxx61
-rw-r--r--static/source/unoembindhelpers/PrimaryBindings.cxx9
2 files changed, 59 insertions, 11 deletions
diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx
index a0ea41eddf97..a3558e5b4e04 100644
--- a/static/source/embindmaker/embindmaker.cxx
+++ b/static/source/embindmaker/embindmaker.cxx
@@ -141,8 +141,8 @@ OUString jsSingleton(OUString const& singleton) { return "uno_Function_" + jsNam
void scan(rtl::Reference<unoidl::MapCursor> const& cursor, std::u16string_view prefix,
Module* module, std::vector<OUString>& enums, std::vector<OUString>& structs,
- std::vector<OUString>& interfaces, std::vector<OUString>& services,
- std::vector<OUString>& singletons)
+ std::vector<OUString>& exceptions, std::vector<OUString>& interfaces,
+ std::vector<OUString>& services, std::vector<OUString>& singletons)
{
assert(cursor.is());
assert(module != nullptr);
@@ -165,8 +165,8 @@ 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(), enums, structs, interfaces, services,
- singletons);
+ Concat2View(name + "."), sub.get(), enums, structs, exceptions, interfaces,
+ services, singletons);
break;
}
case unoidl::Entity::SORT_ENUM_TYPE:
@@ -177,6 +177,10 @@ void scan(rtl::Reference<unoidl::MapCursor> const& cursor, std::u16string_view p
module->mappings.emplace_back(id, "instance.uno_Type_" + jsName(name));
structs.emplace_back(name);
break;
+ case unoidl::Entity::SORT_EXCEPTION_TYPE:
+ module->mappings.emplace_back(id, "instance.uno_Type_" + jsName(name));
+ exceptions.emplace_back(name);
+ break;
case unoidl::Entity::SORT_INTERFACE_TYPE:
module->mappings.emplace_back(id, "instance.uno_Type_" + jsName(name));
interfaces.emplace_back(name);
@@ -449,6 +453,28 @@ void dumpStructMembers(std::ostream& out, rtl::Reference<TypeManager> const& man
}
}
+void dumpExceptionMembers(std::ostream& out, rtl::Reference<TypeManager> const& manager,
+ OUString const& name,
+ rtl::Reference<unoidl::ExceptionTypeEntity> exception)
+{
+ auto const& base = exception->getDirectBase();
+ if (!base.isEmpty())
+ {
+ auto const ent = manager->getManager()->findEntity(base);
+ if (!ent.is() || ent->getSort() != unoidl::Entity::SORT_EXCEPTION_TYPE)
+ {
+ throw CannotDumpException("bad exception base \"" + base + "\"");
+ }
+ dumpExceptionMembers(out, manager, name,
+ static_cast<unoidl::ExceptionTypeEntity*>(ent.get()));
+ }
+ for (auto const& mem : exception->getDirectMembers())
+ {
+ out << "\n .field(\"" << mem.name << "\", &" << cppName(name) << "::" << mem.name
+ << ")";
+ }
+}
+
void dumpAttributes(std::ostream& out, rtl::Reference<TypeManager> const& manager,
OUString const& name, rtl::Reference<unoidl::InterfaceTypeEntity> const& entity,
std::list<OUString> const& baseTrail)
@@ -784,13 +810,14 @@ SAL_IMPLEMENT_MAIN()
auto const module = std::make_shared<Module>();
std::vector<OUString> enums;
std::vector<OUString> structs;
+ std::vector<OUString> exceptions;
std::vector<OUString> interfaces;
std::vector<OUString> services;
std::vector<OUString> singletons;
for (auto const& prov : mgr->getPrimaryProviders())
{
- scan(prov->createRootCursor(), u"", module.get(), enums, structs, interfaces, services,
- singletons);
+ scan(prov->createRootCursor(), u"", module.get(), enums, structs, exceptions,
+ interfaces, services, singletons);
}
std::ofstream cppOut(cppPathname, std::ios_base::out | std::ios_base::trunc);
if (!cppOut)
@@ -810,6 +837,10 @@ SAL_IMPLEMENT_MAIN()
{
cppOut << "#include <" << str.replace('.', '/') << ".hpp>\n";
}
+ for (auto const& exc : exceptions)
+ {
+ cppOut << "#include <" << exc.replace('.', '/') << ".hpp>\n";
+ }
for (auto const& ifc : interfaces)
{
cppOut << "#include <" << ifc.replace('.', '/') << ".hpp>\n";
@@ -871,6 +902,24 @@ SAL_IMPLEMENT_MAIN()
recordSequenceTypes(mgr, mem.type, sequences);
}
}
+ for (auto const& exc : exceptions)
+ {
+ auto const ent = mgr->getManager()->findEntity(exc);
+ assert(ent.is());
+ assert(ent->getSort() == unoidl::Entity::SORT_EXCEPTION_TYPE);
+ rtl::Reference const excEnt(static_cast<unoidl::ExceptionTypeEntity*>(ent.get()));
+ dumpRegisterFunctionProlog(cppOut, n);
+ cppOut << " ::emscripten::value_object<" << cppName(exc) << ">(\"uno_Type_"
+ << jsName(exc) << "\")";
+ dumpExceptionMembers(cppOut, mgr, exc, excEnt);
+ cppOut << ";\n";
+ cppOut << " ::unoembindhelpers::registerUnoType<" << cppName(exc) << ">();\n";
+ dumpRegisterFunctionEpilog(cppOut, n);
+ for (auto const& mem : excEnt->getDirectMembers())
+ {
+ recordSequenceTypes(mgr, mem.type, sequences);
+ }
+ }
for (auto const& ifc : interfaces)
{
auto const ent = mgr->getManager()->findEntity(ifc);
diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx
index 21fe4c1cd66f..93ae89531a00 100644
--- a/static/source/unoembindhelpers/PrimaryBindings.cxx
+++ b/static/source/unoembindhelpers/PrimaryBindings.cxx
@@ -318,18 +318,17 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
_emval_take_value(getTypeId(self.getValueType()), argv));
}
case css::uno::TypeClass_STRUCT:
+ case css::uno::TypeClass_EXCEPTION:
{
css::uno::TypeDescription desc(self.getValueType().getTypeLibType());
assert(desc.is());
- auto const td = reinterpret_cast<typelib_StructTypeDescription*>(desc.get());
- auto const copy = std::malloc(td->aBase.aBase.nSize);
- copyStruct(&td->aBase, self.getValue(), copy);
+ auto const td = reinterpret_cast<typelib_CompoundTypeDescription*>(desc.get());
+ auto const copy = std::malloc(td->aBase.nSize);
+ copyStruct(td, self.getValue(), copy);
emscripten::internal::WireTypePack argv(std::move(copy));
return emscripten::val::take_ownership(
_emval_take_value(getTypeId(self.getValueType()), argv));
}
- case css::uno::TypeClass_EXCEPTION:
- return emscripten::val::undefined(); //TODO
case css::uno::TypeClass_INTERFACE:
return emscripten::val::undefined(); //TODO
default: