summaryrefslogtreecommitdiff
path: root/codemaker/source/cppumaker/cpputype.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'codemaker/source/cppumaker/cpputype.cxx')
-rw-r--r--codemaker/source/cppumaker/cpputype.cxx158
1 files changed, 99 insertions, 59 deletions
diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx
index dab77fa42292..b2ba3413402c 100644
--- a/codemaker/source/cppumaker/cpputype.cxx
+++ b/codemaker/source/cppumaker/cpputype.cxx
@@ -27,6 +27,7 @@
#include <set>
#include <string_view>
#include <memory>
+#include <utility>
#include <vector>
#include <iostream>
@@ -52,6 +53,8 @@
namespace
{
+using FileType = codemaker::cppumaker::FileType;
+
bool isBootstrapType(OUString const & name)
{
static char const * const names[] = {
@@ -143,19 +146,26 @@ bool isBootstrapType(OUString const & name)
"com.sun.star.uno.XWeak",
"com.sun.star.util.XMacroExpander" };
// cf. cppuhelper/unotypes/Makefile UNOTYPES (plus missing dependencies)
- for (std::size_t i = 0; i < SAL_N_ELEMENTS(names); ++i) {
- if (name.equalsAscii(names[i])) {
- return true;
- }
+ auto const pred = [&name](const char* aName) {
+ return name.equalsAscii(aName);
+ };
+ return std::any_of(std::begin(names), std::end(names), pred);
+}
+
+OString getFileExtension(FileType eFileType)
+{
+ switch(eFileType)
+ {
+ default:
+ case FileType::HDL: return ".hdl"_ostr;
+ case FileType::HPP: return ".hpp"_ostr;
}
- return false;
}
class CppuType
{
public:
- CppuType(
- OUString const & name, rtl::Reference< TypeManager > const & typeMgr);
+ CppuType(OUString name, rtl::Reference< TypeManager > const & typeMgr);
virtual ~CppuType() {}
@@ -165,7 +175,7 @@ public:
void dump(CppuOptions const & options);
void dumpFile(
- std::u16string_view uri, std::u16string_view name, bool hpp,
+ std::u16string_view uri, std::u16string_view name, FileType eFileType,
CppuOptions const & options);
void dumpDependedTypes(
@@ -275,12 +285,12 @@ private:
};
CppuType::CppuType(
- OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
+ OUString name, rtl::Reference< TypeManager > const & typeMgr):
m_inheritedMemberCount(0)
, m_cppuTypeLeak(false)
, m_cppuTypeDynamic(true)
, m_indentLength(0)
- , name_(name)
+ , name_(std::move(name))
, id_(name_.copy(name_.lastIndexOf('.') + 1))
, m_typeMgr(typeMgr)
, m_dependencies(typeMgr, name_)
@@ -307,8 +317,8 @@ const
void CppuType::dumpFiles(OUString const & uri, CppuOptions const & options)
{
- dumpFile(uri, name_, false, options);
- dumpFile(uri, name_, true, options);
+ dumpFile(uri, name_, FileType::HDL, options);
+ dumpFile(uri, name_, FileType::HPP, options);
}
void CppuType::addLightGetCppuTypeIncludes(
@@ -403,27 +413,27 @@ void CppuType::dump(CppuOptions const & options)
// functions; since the introduction of cppu::UnoType this no longer is
// meaningful (getCppuType is just a forward to cppu::UnoType::get now),
// and -CS is handled the same way as -C now:
- if (options.isValid("-L"))
+ if (options.isValid("-L"_ostr))
m_cppuTypeLeak = true;
- if (options.isValid("-C") || options.isValid("-CS"))
+ if (options.isValid("-C"_ostr) || options.isValid("-CS"_ostr))
m_cppuTypeDynamic = false;
}
dumpFiles(
- options.isValid("-O") ? b2u(options.getOption("-O")) : "", options);
+ options.isValid("-O"_ostr) ? b2u(options.getOption("-O"_ostr)) : "", options);
}
void CppuType::dumpFile(
- std::u16string_view uri, std::u16string_view name, bool hpp,
+ std::u16string_view uri, std::u16string_view name, FileType eFileType,
CppuOptions const & options)
{
OUString fileUri(
b2u(createFileNameFromType(
- u2b(uri), u2b(name), hpp ? ".hpp" : ".hdl")));
+ u2b(uri), u2b(name), getFileExtension(eFileType))));
if (fileUri.isEmpty()) {
throw CannotDumpException(OUString::Concat("empty target URI for entity ") + name);
}
bool exists = fileExists(u2b(fileUri));
- if (exists && options.isValid("-G")) {
+ if (exists && options.isValid("-G"_ostr)) {
return;
}
FileStream out;
@@ -432,13 +442,17 @@ void CppuType::dumpFile(
if(!out.isValid()) {
throw CannotDumpException("cannot open " + tmpUri + " for writing");
}
- codemaker::cppumaker::Includes includes(m_typeMgr, m_dependencies, hpp);
+ codemaker::cppumaker::Includes includes(m_typeMgr, m_dependencies, eFileType);
try {
- if (hpp) {
- addGetCppuTypeIncludes(includes);
- dumpHppFile(out, includes);
- } else {
- dumpHdlFile(out, includes);
+ switch(eFileType)
+ {
+ case FileType::HPP:
+ addGetCppuTypeIncludes(includes);
+ dumpHppFile(out, includes);
+ break;
+ case FileType::HDL:
+ dumpHdlFile(out, includes);
+ break;
}
} catch (...) {
out.close();
@@ -452,13 +466,13 @@ void CppuType::dumpFile(
}
out.close();
(void)makeValidTypeFile(
- u2b(fileUri), u2b(tmpUri), exists && options.isValid("-Gc"));
+ u2b(fileUri), u2b(tmpUri), exists && options.isValid("-Gc"_ostr));
}
void CppuType::dumpDependedTypes(
codemaker::GeneratedTypeSet & generated, CppuOptions const & options) const
{
- if (!options.isValid("-nD")) {
+ if (!options.isValid("-nD"_ostr)) {
codemaker::cppumaker::Dependencies::Map const & map
= m_dependencies.getMap();
for (const auto& entry : map) {
@@ -1053,9 +1067,9 @@ class BaseOffset
{
public:
BaseOffset(
- rtl::Reference< TypeManager > const & manager,
+ rtl::Reference< TypeManager > manager,
rtl::Reference< unoidl::InterfaceTypeEntity > const & entity):
- manager_(manager), offset_(0) {
+ manager_(std::move(manager)), offset_(0) {
calculateBases(entity);
}
BaseOffset(const BaseOffset&) = delete;
@@ -1186,7 +1200,7 @@ void InterfaceType::dumpHppFile(
out << "\n";
addDefaultHxxIncludes(includes);
includes.dump(out, &name_, !(m_cppuTypeLeak || m_cppuTypeDynamic));
- out << "\n";
+ out << "\n#if defined LIBO_INTERNAL_ONLY\n#include <type_traits>\n#endif\n\n";
dumpGetCppuType(out);
out << "\n::css::uno::Type const & "
<< codemaker::cpp::scopedCppName(u2b(name_))
@@ -1196,7 +1210,15 @@ void InterfaceType::dumpHppFile(
dumpType(out, name_, false, false, true);
out << " >::get();\n";
dec();
- out << "}\n\n#endif // "<< headerDefine << "\n";
+ out << "}\n\n#if defined LIBO_INTERNAL_ONLY\nnamespace cppu::detail {\n";
+ if (name_ == "com.sun.star.uno.XInterface") {
+ out << "template<typename> struct IsUnoInterfaceType: ::std::false_type {};\n"
+ "template<typename T> inline constexpr auto isUnoInterfaceType ="
+ " sizeof (T) && IsUnoInterfaceType<T>::value;\n";
+ }
+ out << "template<> struct IsUnoInterfaceType<";
+ dumpType(out, name_, false, false, true);
+ out << ">: ::std::true_type {};\n}\n#endif\n\n#endif // "<< headerDefine << "\n";
}
void InterfaceType::dumpAttributes(FileStream & out) const
@@ -1437,7 +1459,7 @@ void InterfaceType::addComprehensiveGetCppuTypeIncludes(
includes.addCppuUnotypeHxx();
includes.addRtlInstanceHxx(); // using rtl::StaticWithInit
includes.addOslMutexHxx();
- includes.add("com.sun.star.uno.RuntimeException");
+ includes.add("com.sun.star.uno.RuntimeException"_ostr);
}
void InterfaceType::dumpCppuAttributes(FileStream & out, sal_uInt32 & index)
@@ -1713,7 +1735,11 @@ void ConstantGroup::dumpDeclaration(FileStream & out)
out << "double";
break;
}
- out << " " << member.name << " = ";
+ out << " "
+ << codemaker::cpp::translateUnoToCppIdentifier(
+ u2b(member.name), "constant",
+ codemaker::cpp::IdentifierTranslationMode::KeywordsOnly)
+ << " = ";
switch (member.value.type) {
case unoidl::ConstantValue::TYPE_BOOLEAN:
out << (member.value.booleanValue ? "sal_True" : "sal_False");
@@ -2052,8 +2078,10 @@ void PlainStructType::dumpComprehensiveGetCppuType(FileStream & out)
for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
entity_->getDirectMembers().begin());
i != entity_->getDirectMembers().end();) {
+ const auto iter = types.find(i->type);
+ assert(iter != types.end());
out << indent() << "{ { " << getTypeClass(i->type, true)
- << ", the_tname" << types.find(i->type)->second
+ << ", the_tname" << iter->second
<< ".pData, the_name" << n++ << ".pData }, false }";
++i;
out << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n";
@@ -2621,11 +2649,15 @@ void PolyStructType::dumpComprehensiveGetCppuType(FileStream & out)
i != entity_->getMembers().end();) {
out << indent() << "{ { ";
if (i->parameterized) {
- sal_uInt32 k = parameters.find(i->type)->second;
+ const auto iter = parameters.find(i->type);
+ assert(iter != parameters.end());
+ sal_uInt32 k = iter->second;
out << "the_pclass" << k << ", the_pname" << k << ".pData";
} else {
+ const auto iter = types.find(i->type);
+ assert(iter != types.end());
out << getTypeClass(i->type, true) << ", the_tname"
- << types.find(i->type)->second << ".pData";
+ << iter->second << ".pData";
}
out << ", the_name" << n++ << ".pData }, "
<< (i->parameterized ? "true" : "false") << " }";
@@ -2786,15 +2818,19 @@ void ExceptionType::dumpHdlFile(
{
if (name_ == "com.sun.star.uno.Exception")
{
- // LIBO_INTERNAL_ONLY implies GCC >= 7, which we need for this
- // Merely checking __has_include is not enough because some systems have the header,
- // but do not have a new enough Clang 9 supporting __builtin_FILE/LINE/FUNCTION as used by
- // that libstdc++ header.
- includes.addCustom("#if defined LIBO_INTERNAL_ONLY && ((defined __GNUC__ && !defined __clang__) || (defined __clang__ && __clang_major__ >= 9)) && __has_include(<experimental/source_location>)");
- includes.addCustom("#define LIBO_USE_SOURCE_LOCATION");
+ includes.addCustom("#if defined(LIBO_INTERNAL_ONLY)");
+ includes.addCustom("#if __has_include(<version>)");
+ includes.addCustom("#include <version>");
includes.addCustom("#endif");
- includes.addCustom("#if defined LIBO_USE_SOURCE_LOCATION");
+ includes.addCustom("#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907");
+ includes.addCustom("#include <source_location>");
+ includes.addCustom("#define LIBO_USE_SOURCE_LOCATION std");
+ includes.addCustom("#elif __has_include(<experimental/source_location>)");
includes.addCustom("#include <experimental/source_location>");
+ includes.addCustom("#define LIBO_USE_SOURCE_LOCATION std::experimental");
+ includes.addCustom("#endif");
+ includes.addCustom("#endif");
+ includes.addCustom("#if defined LIBO_USE_SOURCE_LOCATION");
includes.addCustom("#include <o3tl/runtimetooustring.hxx>");
includes.addCustom("#endif");
}
@@ -2834,7 +2870,7 @@ void ExceptionType::dumpHppFile(
// default constructor
out << "\ninline " << id_ << "::" << id_ << "(\n";
out << "#if defined LIBO_USE_SOURCE_LOCATION\n";
- out << " std::experimental::source_location location\n";
+ out << " LIBO_USE_SOURCE_LOCATION::source_location location\n";
out << "#endif\n";
out << " )\n";
inc();
@@ -2871,7 +2907,7 @@ void ExceptionType::dumpHppFile(
out << "\n#if defined LIBO_USE_SOURCE_LOCATION\n";
out << " if (!Message.isEmpty())\n";
out << " Message += \" \";\n";
- out << " Message += o3tl::runtimeToOUString(location.file_name()) + \":\" + OUString::number(location.line());\n";
+ out << " Message += \"at \" + o3tl::runtimeToOUString(location.file_name()) + \":\" + OUString::number(location.line());\n";
out << "#endif\n";
}
out << "}\n\n";
@@ -2889,7 +2925,7 @@ void ExceptionType::dumpHppFile(
bFirst = false;
}
out << "\n#if defined LIBO_USE_SOURCE_LOCATION\n";
- out << " " << (bFirst ? "" : ", ") << "std::experimental::source_location location\n";
+ out << " " << (bFirst ? "" : ", ") << "LIBO_USE_SOURCE_LOCATION::source_location location\n";
out << "#endif\n";
out << ")\n";
inc();
@@ -2924,7 +2960,7 @@ void ExceptionType::dumpHppFile(
out << "\n#if defined LIBO_USE_SOURCE_LOCATION\n";
out << " if (!Message.isEmpty())\n";
out << " Message += \" \";\n";
- out << " Message += o3tl::runtimeToOUString(location.file_name()) + \":\" + OUString::number(location.line());\n";
+ out << " Message += \"at \" + o3tl::runtimeToOUString(location.file_name()) + \":\" + OUString::number(location.line());\n";
out << "#endif\n";
}
out << "}\n\n";
@@ -3150,7 +3186,7 @@ void ExceptionType::dumpDeclaration(FileStream & out)
// default constructor
out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(\n";
out << "#if defined LIBO_USE_SOURCE_LOCATION\n";
- out << " std::experimental::source_location location = std::experimental::source_location::current()\n";
+ out << " LIBO_USE_SOURCE_LOCATION::source_location location = LIBO_USE_SOURCE_LOCATION::source_location::current()\n";
out << "#endif\n\n";
out << " );\n";
@@ -3168,7 +3204,7 @@ void ExceptionType::dumpDeclaration(FileStream & out)
bFirst = false;
}
out << "\n#if defined LIBO_USE_SOURCE_LOCATION\n";
- out << ", std::experimental::source_location location = std::experimental::source_location::current()\n";
+ out << ", LIBO_USE_SOURCE_LOCATION::source_location location = LIBO_USE_SOURCE_LOCATION::source_location::current()\n";
out << "#endif\n";
out << " );\n\n";
}
@@ -3292,7 +3328,11 @@ void EnumType::addComprehensiveGetCppuTypeIncludes(
void EnumType::dumpDeclaration(FileStream& o)
{
o << "\n#if defined LIBO_INTERNAL_ONLY\n";
+ o << "\n#if defined __GNUC__\n"; // gcc does not like visibility annotation on enum
+ o << "\nenum class " << id_ << "\n{\n";
+ o << "\n#else\n";
o << "\nenum class SAL_DLLPUBLIC_RTTI " << id_ << "\n{\n";
+ o << "\n#endif\n";
o << "\n#else\n";
o << "\nenum SAL_DLLPUBLIC_RTTI " << id_ << "\n{\n";
o << "\n#endif\n";
@@ -3509,7 +3549,7 @@ private:
}
virtual void dumpFiles(OUString const & uri, CppuOptions const & options) override {
- dumpFile(uri, name_, true, options);
+ dumpFile(uri, name_, FileType::HPP, options);
}
};
@@ -3572,12 +3612,12 @@ void ServiceType::dumpHppFile(
includes.addReference();
includes.addRtlUstringH();
includes.addRtlUstringHxx();
- includes.add("com.sun.star.uno.DeploymentException");
- includes.add("com.sun.star.uno.XComponentContext");
+ includes.add("com.sun.star.uno.DeploymentException"_ostr);
+ includes.add("com.sun.star.uno.XComponentContext"_ostr);
for (const unoidl::SingleInterfaceBasedServiceEntity::Constructor& cons : entity_->getConstructors()) {
if (cons.defaultConstructor) {
- includes.add("com.sun.star.uno.Exception");
- includes.add("com.sun.star.uno.RuntimeException");
+ includes.add("com.sun.star.uno.Exception"_ostr);
+ includes.add("com.sun.star.uno.RuntimeException"_ostr);
} else {
if (!hasRestParameter(cons)) {
includes.addAny();
@@ -3598,8 +3638,8 @@ void ServiceType::dumpHppFile(
tree.add(u2b(ex), m_typeMgr);
}
if (!tree.getRoot().present) {
- includes.add("com.sun.star.uno.Exception");
- includes.add("com.sun.star.uno.RuntimeException");
+ includes.add("com.sun.star.uno.Exception"_ostr);
+ includes.add("com.sun.star.uno.RuntimeException"_ostr);
includeExceptions(includes, &tree.getRoot());
}
}
@@ -3641,7 +3681,7 @@ void ServiceType::dumpHppFile(
o << indent() << "static ::css::uno::Reference< "
<< scopedBaseName << " > "
<< codemaker::cpp::translateUnoToCppIdentifier(
- "create", "method", codemaker::cpp::IdentifierTranslationMode::NonGlobal,
+ "create"_ostr, "method", codemaker::cpp::IdentifierTranslationMode::NonGlobal,
&cppName)
<< ("(::css::uno::Reference< ::css::uno::XComponentContext > const &"
" the_context) {\n");
@@ -3911,8 +3951,8 @@ void SingletonType::dumpHppFile(
o << "\n";
//TODO: Decide whether the types added to includes should rather be added to
// m_dependencies (and thus be generated during dumpDependedTypes):
- includes.add("com.sun.star.uno.DeploymentException");
- includes.add("com.sun.star.uno.XComponentContext");
+ includes.add("com.sun.star.uno.DeploymentException"_ostr);
+ includes.add("com.sun.star.uno.XComponentContext"_ostr);
includes.addCassert();
includes.addAny();
includes.addReference();
@@ -3940,7 +3980,7 @@ void SingletonType::dumpHppFile(
o << indent() << "static ::css::uno::Reference< "
<< scopedBaseName << " > "
<< codemaker::cpp::translateUnoToCppIdentifier(
- "get", "method", codemaker::cpp::IdentifierTranslationMode::NonGlobal, &cppName)
+ "get"_ostr, "method", codemaker::cpp::IdentifierTranslationMode::NonGlobal, &cppName)
<< ("(::css::uno::Reference<"
" ::css::uno::XComponentContext > const & the_context)"
" {\n");