summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-01-31 11:17:26 +0100
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-01-31 15:56:39 +0100
commit702f420ab39b89f568cb4a173286b307e5b9cabf (patch)
tree6c6b9bb474657f55c63a6a00a8c156c30179f4ab
parent788ebd183b095ffb7369c4d518acd14bad72ae82 (diff)
embindmaker: Handle enums
Change-Id: I07e068e52df2a838e76f32e691d23a47d7fcfdda Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162809 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
-rw-r--r--static/README.wasm.md2
-rw-r--r--static/source/embindmaker/embindmaker.cxx35
-rw-r--r--static/source/unoembindhelpers/PrimaryBindings.cxx16
3 files changed, 32 insertions, 21 deletions
diff --git a/static/README.wasm.md b/static/README.wasm.md
index 80e9e75607c0..89c2ac681f4c 100644
--- a/static/README.wasm.md
+++ b/static/README.wasm.md
@@ -249,7 +249,7 @@ while (xParaEnumeration.hasMoreElements()) {
xParagraph = new css.text.XTextRange(xParaEnumeration.nextElement(), Module.uno_Reference.FromAny);
if (xParagraph.$is()) {
xParaProps = new css.beans.XPropertySet(xParagraph.$query());
- xParaProps.setPropertyValue(new Module.OUString("CharColor"), new Module.Any(Math.floor(Math.random() * 0xFFFFFF), Module.UnoType.long));
+ xParaProps.setPropertyValue(new Module.OUString("CharColor"), new Module.Any(Math.floor(Math.random() * 0xFFFFFF), css.uno.TypeClass.LONG));
}
}
```
diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx
index 498e5ff0e551..178e9e41988a 100644
--- a/static/source/embindmaker/embindmaker.cxx
+++ b/static/source/embindmaker/embindmaker.cxx
@@ -139,8 +139,8 @@ jsServiceConstructor(OUString const& service,
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,
- std::vector<OUString>& singletons)
+ Module* module, std::vector<OUString>& enums, std::vector<OUString>& interfaces,
+ std::vector<OUString>& services, std::vector<OUString>& singletons)
{
assert(cursor.is());
assert(module != nullptr);
@@ -163,9 +163,13 @@ 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, singletons);
+ Concat2View(name + "."), sub.get(), enums, interfaces, services, singletons);
break;
}
+ case unoidl::Entity::SORT_ENUM_TYPE:
+ module->mappings.emplace_back(id, "uno_Type_" + jsName(name));
+ enums.emplace_back(name);
+ break;
case unoidl::Entity::SORT_INTERFACE_TYPE:
module->mappings.emplace_back(id, "uno_Type_" + jsName(name));
interfaces.emplace_back(name);
@@ -690,12 +694,14 @@ SAL_IMPLEMENT_MAIN()
}
}
auto const module = std::make_shared<Module>();
+ std::vector<OUString> enums;
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, singletons);
+ scan(prov->createRootCursor(), u"", module.get(), enums, interfaces, services,
+ singletons);
}
std::ofstream cppOut(cppPathname, std::ios_base::out | std::ios_base::trunc);
if (!cppOut)
@@ -707,6 +713,10 @@ SAL_IMPLEMENT_MAIN()
"#include <com/sun/star/uno/Any.hxx>\n"
"#include <com/sun/star/uno/Reference.hxx>\n"
"#include <static/unoembindhelpers/PrimaryBindings.hxx>\n";
+ for (auto const& enm : enums)
+ {
+ cppOut << "#include <" << enm.replace('.', '/') << ".hpp>\n";
+ }
for (auto const& ifc : interfaces)
{
cppOut << "#include <" << ifc.replace('.', '/') << ".hpp>\n";
@@ -731,6 +741,23 @@ SAL_IMPLEMENT_MAIN()
}
cppOut << "}\n\n";
unsigned long long n = 0;
+ for (auto const& enm : enums)
+ {
+ auto const ent = mgr->getManager()->findEntity(enm);
+ assert(ent.is());
+ assert(ent->getSort() == unoidl::Entity::SORT_ENUM_TYPE);
+ rtl::Reference const enmEnt(static_cast<unoidl::EnumTypeEntity*>(ent.get()));
+ dumpRegisterFunctionProlog(cppOut, n);
+ cppOut << " ::emscripten::enum_<" << cppName(enm) << ">(\"uno_Type_" << jsName(enm)
+ << "\")";
+ for (auto const& mem : enmEnt->getMembers())
+ {
+ cppOut << "\n .value(\"" << mem.name << "\", " << cppName(enm) << "_"
+ << mem.name << ")";
+ }
+ cppOut << ";\n";
+ dumpRegisterFunctionEpilog(cppOut, n);
+ }
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 00e2453127b5..f42fb69c3e8f 100644
--- a/static/source/unoembindhelpers/PrimaryBindings.cxx
+++ b/static/source/unoembindhelpers/PrimaryBindings.cxx
@@ -45,22 +45,6 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
return std::u16string(rSelf.getStr(), rSelf.getLength());
});
- // Types used for Any construction
- enum_<TypeClass>("UnoType")
- .value("void", TypeClass::TypeClass_VOID)
- .value("char", TypeClass::TypeClass_CHAR)
- .value("bool", TypeClass::TypeClass_BOOLEAN)
- .value("byte", TypeClass::TypeClass_BYTE)
- .value("short", TypeClass::TypeClass_SHORT)
- .value("unsigned_short", TypeClass::TypeClass_UNSIGNED_SHORT)
- .value("long", TypeClass::TypeClass_LONG)
- .value("unsigned_long", TypeClass::TypeClass_UNSIGNED_LONG)
- .value("hyper", TypeClass::TypeClass_HYPER)
- .value("unsigned_hyper", TypeClass::TypeClass_UNSIGNED_HYPER)
- .value("float", TypeClass::TypeClass_FLOAT)
- .value("double", TypeClass::TypeClass_DOUBLE)
- .value("string", TypeClass::TypeClass_STRING);
-
// Any
class_<Any>("Any").constructor(+[](const val& rObject, const TypeClass& rUnoType) -> Any {
switch (rUnoType)