From 1d0bc2139759f087d50432f8a2116060676f34e1 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 9 May 2020 18:25:33 +0200 Subject: use std::experimental::source_location in uno::Exception Clang and gcc have moved this out of experimental and into std::source_location, but only in their very latest releases. Change-Id: I9d9d9155788ee4240455ac4628b298dface4ad24 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93868 Tested-by: Jenkins Reviewed-by: Noel Grandin --- codemaker/source/cppumaker/cpputype.cxx | 76 ++++++++++++++++++++++++++++++--- codemaker/source/cppumaker/includes.cxx | 2 + codemaker/source/cppumaker/includes.hxx | 4 +- 3 files changed, 76 insertions(+), 6 deletions(-) (limited to 'codemaker') diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx index 12c951205c54..e2288c961133 100644 --- a/codemaker/source/cppumaker/cpputype.cxx +++ b/codemaker/source/cppumaker/cpputype.cxx @@ -2750,6 +2750,9 @@ public: } private: + virtual void dumpHdlFile( + FileStream & out, codemaker::cppumaker::Includes & includes) override; + virtual void dumpHppFile( FileStream & out, codemaker::cppumaker::Includes & includes) override; @@ -2777,6 +2780,25 @@ private: rtl::Reference< unoidl::ExceptionTypeEntity > entity_; }; +void ExceptionType::dumpHdlFile( + FileStream & out, codemaker::cppumaker::Includes & includes) +{ + 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 for it to work. + includes.addCustom("#if defined LIBO_INTERNAL_ONLY && ((defined __GNUC__ && !defined __clang__) || (defined __clang__ && __clang_major__ >= 8)) && __has_include()"); + includes.addCustom("#define LIBO_USE_SOURCE_LOCATION"); + includes.addCustom("#endif"); + includes.addCustom("#if defined LIBO_USE_SOURCE_LOCATION"); + includes.addCustom("#include "); + includes.addCustom("#include "); + includes.addCustom("#endif"); + } + dumpHFileContent(out, includes); +} + void ExceptionType::addComprehensiveGetCppuTypeIncludes( codemaker::cppumaker::Includes & includes) const { @@ -2806,13 +2828,23 @@ void ExceptionType::dumpHppFile( if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) { out << "\n"; } - out << "\ninline " << id_ << "::" << id_ << "()\n"; + + // default constructor + out << "\ninline " << id_ << "::" << id_ << "(\n"; + out << "#if defined LIBO_USE_SOURCE_LOCATION\n"; + out << " std::experimental::source_location location\n"; + out << "#endif\n"; + out << " )\n"; inc(); OUString base(entity_->getDirectBase()); bool bFirst = true; if (!base.isEmpty()) { out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base)) - << "()\n"; + << "(\n"; + out << "#if defined LIBO_USE_SOURCE_LOCATION\n"; + out << " location\n"; + out << "#endif\n"; + out << ")\n"; bFirst = false; } for (const unoidl::ExceptionTypeEntity::Member& member : entity_->getDirectMembers()) { @@ -2832,7 +2864,17 @@ void ExceptionType::dumpHppFile( } else { out << " "; } + if (name_ == "com.sun.star.uno.Exception") + { + 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 << "#endif\n"; + } out << "}\n\n"; + + // fields constructor if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) { out << indent() << "inline " << id_ << "::" << id_ << "("; bFirst = !dumpBaseMembers(out, base, true, false); @@ -2844,6 +2886,9 @@ void ExceptionType::dumpHppFile( out << " " << member.name << "_"; bFirst = false; } + out << "\n#if defined LIBO_USE_SOURCE_LOCATION\n"; + out << " " << (bFirst ? "" : ", ") << "std::experimental::source_location location\n"; + out << "#endif\n"; out << ")\n"; inc(); bFirst = true; @@ -2851,6 +2896,9 @@ void ExceptionType::dumpHppFile( out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base)) << "("; dumpBaseMembers(out, base, false, false); + out << "\n#if defined LIBO_USE_SOURCE_LOCATION\n"; + out << " , location\n"; + out << "#endif\n"; out << ")\n"; bFirst = false; } @@ -2869,6 +2917,14 @@ void ExceptionType::dumpHppFile( } else { out << " "; } + if (name_ == "com.sun.star.uno.Exception") + { + 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 << "#endif\n"; + } out << "}\n\n"; } out << "#if !defined LIBO_INTERNAL_ONLY\n" << indent() << id_ << "::" << id_ @@ -3088,8 +3144,15 @@ void ExceptionType::dumpDeclaration(FileStream & out) } out << "\n{\npublic:\n"; inc(); - out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ - << "();\n\n"; + + // 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 << "#endif\n\n"; + out << " );\n"; + + // constructor that initializes data members if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) { out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "("; bool eligibleForDefaults = entity_->getDirectMembers().empty(); @@ -3102,7 +3165,10 @@ void ExceptionType::dumpDeclaration(FileStream & out) out << " " << member.name << "_"; bFirst = false; } - out << ");\n\n"; + out << "\n#if defined LIBO_USE_SOURCE_LOCATION\n"; + out << ", std::experimental::source_location location = std::experimental::source_location::current()\n"; + out << "#endif\n"; + out << " );\n\n"; } out << "#if !defined LIBO_INTERNAL_ONLY\n" << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(" << id_ diff --git a/codemaker/source/cppumaker/includes.cxx b/codemaker/source/cppumaker/includes.cxx index 732f5065c191..a07c651bec01 100644 --- a/codemaker/source/cppumaker/includes.cxx +++ b/codemaker/source/cppumaker/includes.cxx @@ -254,6 +254,8 @@ void Includes::dump( dumpEmptyLineBeforeFirst(out, &first); out << "#include \"typelib/typedescription.h\"\n"; } + for (OUString const & s : m_custom) + out << s << "\n"; } void Includes::dumpInclude( diff --git a/codemaker/source/cppumaker/includes.hxx b/codemaker/source/cppumaker/includes.hxx index 0203868374f2..fb193233dea6 100644 --- a/codemaker/source/cppumaker/includes.hxx +++ b/codemaker/source/cppumaker/includes.hxx @@ -22,7 +22,7 @@ #include #include - +#include #include "dependencies.hxx" class FileStream; @@ -58,6 +58,7 @@ public: void addTypelibTypeclassH() { m_includeTypelibTypeclassH = true; } void addTypelibTypedescriptionH() { m_includeTypelibTypedescriptionH = true; } + void addCustom(const OUString& s) { m_custom.push_back(s); } void dump( FileStream & out, OUString const * companionHdl, bool exceptions); @@ -91,6 +92,7 @@ private: bool m_includeSalTypesH; bool m_includeTypelibTypeclassH; bool m_includeTypelibTypedescriptionH; + std::vector m_custom; }; } -- cgit