diff options
Diffstat (limited to 'codemaker/source/cppumaker/cpputype.cxx')
-rw-r--r-- | codemaker/source/cppumaker/cpputype.cxx | 369 |
1 files changed, 205 insertions, 164 deletions
diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx index 221fee39acfc..8d67cdc94e11 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)) : u""_ustr, 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) { @@ -656,86 +670,86 @@ OUString CppuType::getTypeClass(OUString const & name, bool cStyle) switch (m_typeMgr->getSort(name, &ent)) { case codemaker::UnoType::Sort::Void: return cStyle - ? OUString("typelib_TypeClass_VOID") - : OUString("::css::uno::TypeClass_VOID"); + ? u"typelib_TypeClass_VOID"_ustr + : u"::css::uno::TypeClass_VOID"_ustr; case codemaker::UnoType::Sort::Boolean: return cStyle - ? OUString("typelib_TypeClass_BOOLEAN") - : OUString("::css::uno::TypeClass_BOOLEAN"); + ? u"typelib_TypeClass_BOOLEAN"_ustr + : u"::css::uno::TypeClass_BOOLEAN"_ustr; case codemaker::UnoType::Sort::Byte: return cStyle - ? OUString("typelib_TypeClass_BYTE") - : OUString("::css::uno::TypeClass_BYTE"); + ? u"typelib_TypeClass_BYTE"_ustr + : u"::css::uno::TypeClass_BYTE"_ustr; case codemaker::UnoType::Sort::Short: return cStyle - ? OUString("typelib_TypeClass_SHORT") - : OUString("::css::uno::TypeClass_SHORT"); + ? u"typelib_TypeClass_SHORT"_ustr + : u"::css::uno::TypeClass_SHORT"_ustr; case codemaker::UnoType::Sort::UnsignedShort: return cStyle - ? OUString("typelib_TypeClass_UNSIGNED_SHORT") - : OUString("::css::uno::TypeClass_UNSIGNED_SHORT"); + ? u"typelib_TypeClass_UNSIGNED_SHORT"_ustr + : u"::css::uno::TypeClass_UNSIGNED_SHORT"_ustr; case codemaker::UnoType::Sort::Long: return cStyle - ? OUString("typelib_TypeClass_LONG") - : OUString("::css::uno::TypeClass_LONG"); + ? u"typelib_TypeClass_LONG"_ustr + : u"::css::uno::TypeClass_LONG"_ustr; case codemaker::UnoType::Sort::UnsignedLong: return cStyle - ? OUString("typelib_TypeClass_UNSIGNED_LONG") - : OUString("::css::uno::TypeClass_UNSIGNED_LONG"); + ? u"typelib_TypeClass_UNSIGNED_LONG"_ustr + : u"::css::uno::TypeClass_UNSIGNED_LONG"_ustr; case codemaker::UnoType::Sort::Hyper: return cStyle - ? OUString("typelib_TypeClass_HYPER") - : OUString("::css::uno::TypeClass_HYPER"); + ? u"typelib_TypeClass_HYPER"_ustr + : u"::css::uno::TypeClass_HYPER"_ustr; case codemaker::UnoType::Sort::UnsignedHyper: return cStyle - ? OUString("typelib_TypeClass_UNSIGNED_HYPER") - : OUString("::css::uno::TypeClass_UNSIGNED_HYPER"); + ? u"typelib_TypeClass_UNSIGNED_HYPER"_ustr + : u"::css::uno::TypeClass_UNSIGNED_HYPER"_ustr; case codemaker::UnoType::Sort::Float: return cStyle - ? OUString("typelib_TypeClass_FLOAT") - : OUString("::css::uno::TypeClass_FLOAT"); + ? u"typelib_TypeClass_FLOAT"_ustr + : u"::css::uno::TypeClass_FLOAT"_ustr; case codemaker::UnoType::Sort::Double: return cStyle - ? OUString("typelib_TypeClass_DOUBLE") - : OUString("::css::uno::TypeClass_DOUBLE"); + ? u"typelib_TypeClass_DOUBLE"_ustr + : u"::css::uno::TypeClass_DOUBLE"_ustr; case codemaker::UnoType::Sort::Char: return cStyle - ? OUString("typelib_TypeClass_CHAR") - : OUString("::css::uno::TypeClass_CHAR"); + ? u"typelib_TypeClass_CHAR"_ustr + : u"::css::uno::TypeClass_CHAR"_ustr; case codemaker::UnoType::Sort::String: return cStyle - ? OUString("typelib_TypeClass_STRING") - : OUString("::css::uno::TypeClass_STRING"); + ? u"typelib_TypeClass_STRING"_ustr + : u"::css::uno::TypeClass_STRING"_ustr; case codemaker::UnoType::Sort::Type: return cStyle - ? OUString("typelib_TypeClass_TYPE") - : OUString("::css::uno::TypeClass_TYPE"); + ? u"typelib_TypeClass_TYPE"_ustr + : u"::css::uno::TypeClass_TYPE"_ustr; case codemaker::UnoType::Sort::Any: return cStyle - ? OUString("typelib_TypeClass_ANY") - : OUString("::css::uno::TypeClass_ANY"); + ? u"typelib_TypeClass_ANY"_ustr + : u"::css::uno::TypeClass_ANY"_ustr; case codemaker::UnoType::Sort::Sequence: return cStyle - ? OUString("typelib_TypeClass_SEQUENCE") - : OUString("::css::uno::TypeClass_SEQUENCE"); + ? u"typelib_TypeClass_SEQUENCE"_ustr + : u"::css::uno::TypeClass_SEQUENCE"_ustr; case codemaker::UnoType::Sort::Enum: return cStyle - ? OUString("typelib_TypeClass_ENUM") - : OUString("::css::uno::TypeClass_ENUM"); + ? u"typelib_TypeClass_ENUM"_ustr + : u"::css::uno::TypeClass_ENUM"_ustr; case codemaker::UnoType::Sort::PlainStruct: case codemaker::UnoType::Sort::PolymorphicStructTemplate: case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct: return cStyle - ? OUString("typelib_TypeClass_STRUCT") - : OUString("::css::uno::TypeClass_STRUCT"); + ? u"typelib_TypeClass_STRUCT"_ustr + : u"::css::uno::TypeClass_STRUCT"_ustr; case codemaker::UnoType::Sort::Exception: return cStyle - ? OUString("typelib_TypeClass_EXCEPTION") - : OUString("::css::uno::TypeClass_EXCEPTION"); + ? u"typelib_TypeClass_EXCEPTION"_ustr + : u"::css::uno::TypeClass_EXCEPTION"_ustr; case codemaker::UnoType::Sort::Interface: return cStyle - ? OUString("typelib_TypeClass_INTERFACE") - : OUString("::css::uno::TypeClass_INTERFACE"); + ? u"typelib_TypeClass_INTERFACE"_ustr + : u"::css::uno::TypeClass_INTERFACE"_ustr; case codemaker::UnoType::Sort::Typedef: return getTypeClass(dynamic_cast<unoidl::TypedefEntity&>(*ent).getType(), cStyle); default: @@ -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 @@ -1375,7 +1397,7 @@ void InterfaceType::dumpComprehensiveGetCppuType(FileStream & out) << indent() << "bInitStarted = true;\n"; std::set< OUString > seen; // Type for RuntimeException is always needed: - seen.insert("com.sun.star.uno.RuntimeException"); + seen.insert(u"com.sun.star.uno.RuntimeException"_ustr); dumpCppuGetType(out, u"com.sun.star.uno.RuntimeException"); dumpAttributesCppuDecl(out, &seen); dumpMethodsCppuDecl(out, &seen); @@ -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"; @@ -2088,33 +2116,33 @@ void PlainStructType::dumpComprehensiveGetCppuType(FileStream & out) bool PlainStructType::dumpBaseMembers( FileStream & out, OUString const & base, bool withType) { - bool hasMember = false; - if (!base.isEmpty()) { - rtl::Reference< unoidl::Entity > ent; - codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent); - if (sort != codemaker::UnoType::Sort::PlainStruct) { - throw CannotDumpException( - "plain struct type base " + base - + " is not a plain struct type"); - } - rtl::Reference< unoidl::PlainStructTypeEntity > ent2( - dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get())); - assert(ent2.is()); - if (!ent2.is()) { - return false; + if (base.isEmpty()) + return false; + + rtl::Reference< unoidl::Entity > ent; + codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent); + if (sort != codemaker::UnoType::Sort::PlainStruct) { + throw CannotDumpException( + "plain struct type base " + base + + " is not a plain struct type"); + } + rtl::Reference< unoidl::PlainStructTypeEntity > ent2( + dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get())); + assert(ent2.is()); + if (!ent2.is()) { + return false; + } + bool hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType); + for (const unoidl::PlainStructTypeEntity::Member& member : ent2->getDirectMembers()) { + if (hasMember) { + out << ", "; } - hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType); - for (const unoidl::PlainStructTypeEntity::Member& member : ent2->getDirectMembers()) { - if (hasMember) { - out << ", "; - } - if (withType) { - dumpType(out, member.type, true, true); - out << " "; - } - out << member.name << "_"; - hasMember = true; + if (withType) { + dumpType(out, member.type, true, true); + out << " "; } + out << member.name << "_"; + hasMember = true; } return hasMember; } @@ -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,17 +2818,21 @@ 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("#endif"); - includes.addCustom("#if defined LIBO_USE_SOURCE_LOCATION"); - includes.addCustom("#include <experimental/source_location>"); - includes.addCustom("#include <o3tl/runtimetooustring.hxx>"); - includes.addCustom("#endif"); + includes.addCustom(u"#if defined(LIBO_INTERNAL_ONLY)"_ustr); + includes.addCustom(u"#if __has_include(<version>)"_ustr); + includes.addCustom(u"#include <version>"_ustr); + includes.addCustom(u"#endif"_ustr); + includes.addCustom(u"#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907"_ustr); + includes.addCustom(u"#include <source_location>"_ustr); + includes.addCustom(u"#define LIBO_USE_SOURCE_LOCATION std"_ustr); + includes.addCustom(u"#elif __has_include(<experimental/source_location>)"_ustr); + includes.addCustom(u"#include <experimental/source_location>"_ustr); + includes.addCustom(u"#define LIBO_USE_SOURCE_LOCATION std::experimental"_ustr); + includes.addCustom(u"#endif"_ustr); + includes.addCustom(u"#endif"_ustr); + includes.addCustom(u"#if defined LIBO_USE_SOURCE_LOCATION"_ustr); + includes.addCustom(u"#include <o3tl/runtimetooustring.hxx>"_ustr); + includes.addCustom(u"#endif"_ustr); } dumpHFileContent(out, includes); } @@ -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"; } @@ -3198,45 +3234,46 @@ void ExceptionType::dumpDeclaration(FileStream & out) bool ExceptionType::dumpBaseMembers( FileStream & out, OUString const & base, bool withType, bool eligibleForDefaults) { + if (base.isEmpty()) + return false; + bool hasMember = false; - if (!base.isEmpty()) { - rtl::Reference< unoidl::Entity > ent; - codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent); - if (sort != codemaker::UnoType::Sort::Exception) { - throw CannotDumpException( - "exception type base " + base + " is not an exception type"); + rtl::Reference< unoidl::Entity > ent; + codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent); + if (sort != codemaker::UnoType::Sort::Exception) { + throw CannotDumpException( + "exception type base " + base + " is not an exception type"); + } + rtl::Reference< unoidl::ExceptionTypeEntity > ent2( + dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get())); + assert(ent2.is()); + if (!ent2.is()) { + return false; + } + hasMember = dumpBaseMembers( out, ent2->getDirectBase(), withType, + eligibleForDefaults && ent2->getDirectMembers().empty() ); + int memberCount = 0; + for (const unoidl::ExceptionTypeEntity::Member& member : ent2->getDirectMembers()) { + if (hasMember) { + out << ", "; } - rtl::Reference< unoidl::ExceptionTypeEntity > ent2( - dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get())); - assert(ent2.is()); - if (!ent2.is()) { - return false; + if (withType) { + dumpType(out, member.type, true, true); + out << " "; } - hasMember = dumpBaseMembers( out, ent2->getDirectBase(), withType, - eligibleForDefaults && ent2->getDirectMembers().empty() ); - int memberCount = 0; - for (const unoidl::ExceptionTypeEntity::Member& member : ent2->getDirectMembers()) { - if (hasMember) { - out << ", "; - } - if (withType) { - dumpType(out, member.type, true, true); - out << " "; - } - out << member.name << "_"; - // We want to provide a default parameter value for uno::Exception subtype - // constructors, since most of the time we don't pass a Context object in to the exception - // throw sites. - if (eligibleForDefaults - && base == "com.sun.star.uno.Exception" - && memberCount == 1 - && member.name == "Context" - && member.type == "com.sun.star.uno.XInterface") { - out << " = ::css::uno::Reference< ::css::uno::XInterface >()"; - } - hasMember = true; - ++memberCount; + out << member.name << "_"; + // We want to provide a default parameter value for uno::Exception subtype + // constructors, since most of the time we don't pass a Context object in to the exception + // throw sites. + if (eligibleForDefaults + && base == "com.sun.star.uno.Exception" + && memberCount == 1 + && member.name == "Context" + && member.type == "com.sun.star.uno.XInterface") { + out << " = ::css::uno::Reference< ::css::uno::XInterface >()"; } + hasMember = true; + ++memberCount; } return hasMember; } @@ -3291,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"; @@ -3508,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); } }; @@ -3571,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(); @@ -3597,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()); } } @@ -3640,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"); @@ -3910,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(); @@ -3939,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"); |