summaryrefslogtreecommitdiffstats
path: root/codemaker
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-01-21 14:50:15 +0100
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-01-21 15:51:39 +0100
commitb2ade3e63e34556cad8157e25f8c75d29e79537d (patch)
tree3d268145cc15bedf0d1860c2285ba37c5d62969f /codemaker
parentwriterfilter : use constexpr frozen unordered_set instead of std::unordered_set (diff)
downloadcore-b2ade3e63e34556cad8157e25f8c75d29e79537d.tar.gz
core-b2ade3e63e34556cad8157e25f8c75d29e79537d.zip
Extract embindmaker from cppumaker into its own tool
...that directly generates one large .cxx Change-Id: I046539b83f8fde5eda7168c93a8b819137399665 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162343 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'codemaker')
-rw-r--r--codemaker/source/cppumaker/cppuoptions.cxx18
-rw-r--r--codemaker/source/cppumaker/cpputype.cxx204
-rw-r--r--codemaker/source/cppumaker/cpputype.hxx3
-rw-r--r--codemaker/source/cppumaker/dumputils.cxx14
-rw-r--r--codemaker/source/cppumaker/dumputils.hxx3
5 files changed, 1 insertions, 241 deletions
diff --git a/codemaker/source/cppumaker/cppuoptions.cxx b/codemaker/source/cppumaker/cppuoptions.cxx
index 548b4d369a8e..d16c7dacecba 100644
--- a/codemaker/source/cppumaker/cppuoptions.cxx
+++ b/codemaker/source/cppumaker/cppuoptions.cxx
@@ -216,24 +216,6 @@ bool CppuOptions::initOptions(int ac, char* av[], bool bCmdFile)
m_options["-G"_ostr] = OString();
break;
- case 'W': // generate embind javascript bindings for LOWA
- if (av[i][2] != '\0')
- {
- OString tmp("'-W', please check"_ostr);
- if (i <= ac - 1)
- {
- tmp += OString::Concat(" your input '") + av[i] + "'";
- }
-
- throw IllegalArgument(tmp);
- }
-
- if (!isValid("-C"_ostr) && !isValid("-CS"_ostr) && !isValid("-L"_ostr))
- {
- throw IllegalArgument("'-W' requires '-C' or '-CS' or '-L' option"_ostr);
- }
- m_options["-W"_ostr] = OString();
- break;
case 'X': // support for eXtra type rdbs
{
if (av[i][2] == '\0')
diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx
index 2b995e1d31ae..9ae5d689072e 100644
--- a/codemaker/source/cppumaker/cpputype.cxx
+++ b/codemaker/source/cppumaker/cpputype.cxx
@@ -159,7 +159,6 @@ OString getFileExtension(FileType eFileType)
default:
case FileType::HDL: return ".hdl"_ostr;
case FileType::HPP: return ".hpp"_ostr;
- case FileType::EMBIND_CXX: return "_embind.cxx"_ostr;
}
}
@@ -189,8 +188,6 @@ public:
virtual void dumpHppFile(FileStream& o, codemaker::cppumaker::Includes & includes) = 0;
- void dumpEmbindCppFile(FileStream& o);
-
OUString dumpHeaderDefine(FileStream& o, std::u16string_view extension) const;
void dumpGetCppuType(FileStream & out);
@@ -241,8 +238,6 @@ protected:
assert(false); // this cannot happen
}
- virtual void dumpEmbindDeclaration(FileStream &) {};
-
virtual void dumpFiles(OUString const & uri, CppuOptions const & options);
virtual void addLightGetCppuTypeIncludes(
@@ -324,8 +319,6 @@ void CppuType::dumpFiles(OUString const & uri, CppuOptions const & options)
{
dumpFile(uri, name_, FileType::HDL, options);
dumpFile(uri, name_, FileType::HPP, options);
- if(options.isValid("-W"_ostr))
- dumpFile(uri, name_, FileType::EMBIND_CXX, options);
}
void CppuType::addLightGetCppuTypeIncludes(
@@ -460,9 +453,6 @@ void CppuType::dumpFile(
case FileType::HDL:
dumpHdlFile(out, includes);
break;
- case FileType::EMBIND_CXX:
- dumpEmbindCppFile(out);
- break;
}
} catch (...) {
out.close();
@@ -608,13 +598,6 @@ void CppuType::dumpHFileContent(
out << " *);\n\n#endif\n";
}
-void CppuType::dumpEmbindCppFile(FileStream &out)
-{
- out << "#include <emscripten/bind.h>\n"
- "#include <" << name_.replace('.', '/') << ".hpp>\n";
- dumpEmbindDeclaration(out);
-}
-
void CppuType::dumpGetCppuType(FileStream & out)
{
if (name_ == "com.sun.star.uno.XInterface") {
@@ -1136,14 +1119,10 @@ public:
OUString const & name, rtl::Reference< TypeManager > const & typeMgr);
virtual void dumpDeclaration(FileStream& o) override;
- virtual void dumpEmbindDeclaration(FileStream& o) override;
void dumpHppFile(FileStream& o, codemaker::cppumaker::Includes & includes) override;
void dumpAttributes(FileStream& o) const;
- void dumpEmbindAttributeBindings(FileStream& o) const;
void dumpMethods(FileStream& o) const;
- void dumpEmbindMethodBindings(FileStream& o, bool bDumpForReference=false) const;
- void dumpEmbindWrapperFunc(FileStream& o, const unoidl::InterfaceTypeEntity::Method& method, bool bDumpForReference=false) const;
void dumpNormalGetCppuType(FileStream& o) override;
void dumpComprehensiveGetCppuType(FileStream& o) override;
void dumpCppuAttributeRefs(FileStream& o, sal_uInt32& index);
@@ -1214,53 +1193,6 @@ void InterfaceType::dumpDeclaration(FileStream & out)
out << "};\n\n";
}
-void InterfaceType::dumpEmbindDeclaration(FileStream & out)
-{
- // TODO: This is a temporary workaround that likely causes the Embind UNO
- // bindings to leak memory. Reference counting and cloning mechanisms of
- // Embind should be investigated to figure out what exactly we need here.
- out << "namespace emscripten { namespace internal { \n"
- "template<> void raw_destructor<" << codemaker::cpp::scopedCppName(u2b(name_))
- << ">(" << codemaker::cpp::scopedCppName(u2b(name_)) << "*){}\n"
- "}}\n";
-
- out << "EMSCRIPTEN_BINDINGS(uno_bindings_";
- codemaker::cppumaker::dumpTypeFullWithDecorator(out, name_, u"_");
- codemaker::cppumaker::dumpTypeIdentifier(out, name_);
- out << ") {\n";
-
- out << "\n::emscripten::class_<" << codemaker::cpp::scopedCppName(u2b(name_)) << ">(\"";
- codemaker::cppumaker::dumpTypeFullWithDecorator(out, name_, u"$");
- codemaker::cppumaker::dumpTypeIdentifier(out, name_);
- out << "\")\n";
-
- inc();
- // dump bindings for attributes and methods.
- dumpEmbindAttributeBindings(out);
- dumpEmbindMethodBindings(out);
- out << indent() << ";\n";
- dec();
-
- // dump reference bindings.
- out << "\n::emscripten::class_<::css::uno::Reference<" << codemaker::cpp::scopedCppName(u2b(name_)) << ">, ::emscripten::base<::css::uno::BaseReference>>(\"";
- codemaker::cppumaker::dumpTypeFullWithDecorator(out, name_, u"$");
- codemaker::cppumaker::dumpTypeIdentifier(out, name_);
- out << "Ref\")\n";
- inc();
- out << indent() << ".constructor<>()\n"
- << indent() << ".constructor<::css::uno::BaseReference, ::css::uno::UnoReference_Query>()\n"
- << indent() << ".function(\"is\", &::css::uno::Reference<" << codemaker::cpp::scopedCppName(u2b(name_)) << ">::is)\n"
- << indent() << ".function(\"get\", &::css::uno::Reference<" << codemaker::cpp::scopedCppName(u2b(name_)) << ">::get, ::emscripten::allow_raw_pointers())\n"
- << indent() << ".function(\"set\", ::emscripten::select_overload<bool(const ::css::uno::Any&, com::sun::star::uno::UnoReference_Query)>(&::css::uno::Reference<" << codemaker::cpp::scopedCppName(u2b(name_)) << ">::set))\n";
- dumpEmbindAttributeBindings(out);
- dumpEmbindMethodBindings(out, true);
- out << indent() << ";\n";
- dec();
-
- out << "}\n";
-}
-
-
void InterfaceType::dumpHppFile(
FileStream & out, codemaker::cppumaker::Includes & includes)
{
@@ -1312,31 +1244,6 @@ void InterfaceType::dumpAttributes(FileStream & out) const
}
}
-void InterfaceType::dumpEmbindAttributeBindings(FileStream& out) const
-{
- if (!entity_->getDirectAttributes().empty())
- {
- out << indent() << "// Bindings for attributes\n";
- }
- for (const unoidl::InterfaceTypeEntity::Attribute& attr : entity_->getDirectAttributes())
- {
- if (m_isDeprecated || isDeprecated(attr.annotations))
- continue;
-
- out << indent();
- out << ".function(\"";
- out << "get" << attr.name << "\", &" << codemaker::cpp::scopedCppName(u2b(name_)) << "::get"
- << attr.name << ")\n";
- if (!attr.readOnly)
- {
- out << indent();
- out << ".function(\"";
- out << "set" << attr.name << "\", &" << codemaker::cpp::scopedCppName(u2b(name_))
- << "::set" << attr.name << ")\n";
- }
- }
-}
-
void InterfaceType::dumpMethods(FileStream & out) const
{
if (!entity_->getDirectMethods().empty()) {
@@ -1377,115 +1284,6 @@ void InterfaceType::dumpMethods(FileStream & out) const
}
}
-void InterfaceType::dumpEmbindWrapperFunc(FileStream& out,
- const unoidl::InterfaceTypeEntity::Method& method,
- bool bDumpForReference) const
-{
- out << indent();
- out << ".function(\"" << method.name << "\", ";
- out << indent() << "+[](";
- if (bDumpForReference)
- out << "::css::uno::Reference<";
- out << codemaker::cpp::scopedCppName(u2b(name_));
- if (bDumpForReference)
- out << ">";
- out << "* self";
- if(!method.parameters.empty())
- out << ",";
-
- auto dumpParameters = [&](bool bDumpType)
- {
- // dumpParams with references as pointers
- if (!method.parameters.empty())
- {
- out << " ";
- for (std::vector<unoidl::InterfaceTypeEntity::Method::Parameter>::const_iterator
- parameter(method.parameters.begin());
- parameter != method.parameters.end();)
- {
- bool isConst;
- bool isRef;
- if (parameter->direction
- == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
- {
- isConst = passByReference(parameter->type);
- isRef = isConst;
- }
- else
- {
- isConst = false;
- isRef = true;
- }
- // for the embind wrapper, we define a pointer instead of a reference.
- if (bDumpType)
- dumpType(out, parameter->type, isConst, /*isRef=*/false);
- if (isRef)
- out << "*";
-
- out << " " << parameter->name;
- ++parameter;
- if (parameter != method.parameters.end())
- {
- out << ", ";
- }
- }
- out << " ";
- }
- };
- dumpParameters(/*bDumpType=*/true);
-
- if (bDumpForReference)
- {
- out << ") { return self->get()->" << method.name << "(";
- }
- else
- {
- out << ") { return self->" << method.name << "(";
- }
-
- dumpParameters(/*bDumpType=*/false);
- out << "); }, ::emscripten::allow_raw_pointers() )\n";
-}
-
-void InterfaceType::dumpEmbindMethodBindings(FileStream & out, bool bDumpForReference) const
-{
- if (!entity_->getDirectMethods().empty()) {
- out << indent() << "// Bindings for methods\n";
- }
- for (const unoidl::InterfaceTypeEntity::Method& method : entity_->getDirectMethods()) {
- if( m_isDeprecated || isDeprecated(method.annotations) )
- continue;
-
- // if dumping the method binding for a reference implementation
- // dump wrapper.
- if(bDumpForReference)
- {
- dumpEmbindWrapperFunc(out, method, true);
- continue;
- }
-
- bool bHasOutParams = std::any_of(
- method.parameters.begin(), method.parameters.end(),
- [](const auto& parameter) {
- return parameter.direction
- != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN;
- });
-
- if (bHasOutParams)
- {
- dumpEmbindWrapperFunc(out, method, false);
- continue;
- }
-
- out << indent();
- out << ".function(\"" << method.name << "\", &"
- << codemaker::cpp::scopedCppName(u2b(name_))
- << "::" << method.name << ")\n";
- }
-}
-
-
-
void InterfaceType::dumpNormalGetCppuType(FileStream & out)
{
dumpGetCppuTypePreamble(out);
@@ -3748,8 +3546,6 @@ private:
virtual void dumpFiles(OUString const & uri, CppuOptions const & options) override {
dumpFile(uri, name_, FileType::HPP, options);
- if(options.isValid("-W"_ostr))
- dumpFile(uri, name_, FileType::EMBIND_CXX, options);
}
};
diff --git a/codemaker/source/cppumaker/cpputype.hxx b/codemaker/source/cppumaker/cpputype.hxx
index a6f8f9bfe8a3..c41cfa287646 100644
--- a/codemaker/source/cppumaker/cpputype.hxx
+++ b/codemaker/source/cppumaker/cpputype.hxx
@@ -32,8 +32,7 @@ namespace codemaker::cppumaker {
enum class FileType
{
HDL,
- HPP,
- EMBIND_CXX
+ HPP
};
}
diff --git a/codemaker/source/cppumaker/dumputils.cxx b/codemaker/source/cppumaker/dumputils.cxx
index 54867523b0d4..2a3e809e70f3 100644
--- a/codemaker/source/cppumaker/dumputils.cxx
+++ b/codemaker/source/cppumaker/dumputils.cxx
@@ -74,20 +74,6 @@ void dumpTypeIdentifier(FileStream & out, std::u16string_view entityName) {
out << entityName.substr(entityName.rfind('.') + 1);
}
-bool dumpTypeFullWithDecorator(FileStream& out, std::u16string_view entityName, std::u16string_view decorator)
-{
- bool bOutput = false;
- for (sal_Int32 i = 0; i >= 0;)
- {
- std::u16string_view id(o3tl::getToken(entityName, 0, '.', i));
- if (i >= 0)
- {
- out << id << decorator;
- bOutput = true;
- }
- }
- return bOutput;
-}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/codemaker/source/cppumaker/dumputils.hxx b/codemaker/source/cppumaker/dumputils.hxx
index c7021cba7408..24e5bae3bede 100644
--- a/codemaker/source/cppumaker/dumputils.hxx
+++ b/codemaker/source/cppumaker/dumputils.hxx
@@ -35,9 +35,6 @@ bool dumpNamespaceOpen(FileStream& out, std::u16string_view entityName, bool ful
bool dumpNamespaceClose(FileStream& out, std::u16string_view entityName, bool fullModuleType);
void dumpTypeIdentifier(FileStream& out, std::u16string_view entityName);
-
-bool dumpTypeFullWithDecorator(FileStream& out, std::u16string_view entityName,
- std::u16string_view decorator);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */