diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-06-26 10:43:52 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-06-27 09:47:47 +0000 |
commit | d62278afd55c87101de7c7a9327f06cf5326af0b (patch) | |
tree | 2d3c20ceccff8220b860f84e8051890a4e79d4ed /sources/shiboken2/ApiExtractor/clangparser | |
parent | 4a32f9d00b043b7255b590b95e9b35e9de44c4ed (diff) |
shiboken: No longer hard-code the C++ language level
The C++ language level was previously hard-coded in the default options.
This is potentially problematic for projects using shiboken and also
fell apart with Qt 5.12, where the experimental level "c++1z" used for
MSVC2017/Clang 4 no longer works due to not being able to handle
enumerator value deprecation attributes.
Introduce an enumeration to represent the level and add functions
to convert back to and forth to the respective Clang option.
Add an option to shiboken.
Add a function returning a default value for the emulated compiler,
returning C++ 14 or C++1Z for the CMSVC2017/Clang 4 case.
Task-number: PYSIDE-724
Change-Id: Ie7e19bf7f099a34e6cdaad4b462157a9a3ee8797
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/clangparser')
3 files changed, 65 insertions, 5 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangparser.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangparser.cpp index ddafcdb04..301b4211e 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangparser.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/clangparser.cpp @@ -196,11 +196,6 @@ static CXTranslationUnit createTranslationUnit(CXIndex index, | CXTranslationUnit_Incomplete; static const QByteArrayList defaultArgs = { -#if defined(Q_CC_MSVC) && _MSC_VER > 1900 - "-std=c++1z", // Fixes constexpr errors in MSVC2017 library headers with Clang 4.1 -#else - "-std=c++14", // ! otherwise, t.h is parsed as "C" -#endif #ifndef Q_OS_WIN "-fPIC", #endif diff --git a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp index 9f4f7dc03..820909713 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp @@ -40,12 +40,19 @@ #include <QtCore/QStringList> #include <QtCore/QVersionNumber> +#include <clang-c/Index.h> + #include <string.h> #include <algorithm> #include <iterator> namespace clang { +QVersionNumber libClangVersion() +{ + return QVersionNumber(CINDEX_VERSION_MAJOR, CINDEX_VERSION_MINOR); +} + static bool runProcess(const QString &program, const QStringList &arguments, QByteArray *stdOutIn = nullptr, QByteArray *stdErrIn = nullptr) { @@ -271,4 +278,47 @@ QByteArrayList emulatedCompilerOptions() return result; } +LanguageLevel emulatedCompilerLanguageLevel() +{ +#if defined(Q_CC_MSVC) && _MSC_VER > 1900 + // Fixes constexpr errors in MSVC2017 library headers with Clang 4.1..5.X (0.45 == Clang 6). + if (libClangVersion() < QVersionNumber(0, 45)) + return LanguageLevel::Cpp1Z; +#endif // Q_CC_MSVC && _MSC_VER > 1900 + return LanguageLevel::Cpp14; // otherwise, t.h is parsed as "C" +} + +struct LanguageLevelMapping +{ + const char *option; + LanguageLevel level; +}; + +static const LanguageLevelMapping languageLevelMapping[] = +{ + {"c++11", LanguageLevel::Cpp11}, + {"c++14", LanguageLevel::Cpp14}, + {"c++17", LanguageLevel::Cpp17}, + {"c++20", LanguageLevel::Cpp20}, + {"c++1z", LanguageLevel::Cpp1Z} +}; + +const char *languageLevelOption(LanguageLevel l) +{ + for (const LanguageLevelMapping &m : languageLevelMapping) { + if (m.level == l) + return m.option; + } + return nullptr; +} + +LanguageLevel languageLevelFromOption(const char *o) +{ + for (const LanguageLevelMapping &m : languageLevelMapping) { + if (!strcmp(m.option, o)) + return m.level; + } + return LanguageLevel::Default; +} + } // namespace clang diff --git a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.h b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.h index 68d09f6f5..d9e213e73 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.h +++ b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.h @@ -31,10 +31,25 @@ #include <QtCore/QByteArrayList> +QT_FORWARD_DECLARE_CLASS(QVersionNumber) + +enum class LanguageLevel { + Default, + Cpp11, + Cpp14, + Cpp17, + Cpp20, + Cpp1Z +}; + namespace clang { +QVersionNumber libClangVersion(); QByteArrayList emulatedCompilerOptions(); +LanguageLevel emulatedCompilerLanguageLevel(); +const char *languageLevelOption(LanguageLevel l); +LanguageLevel languageLevelFromOption(const char *); } // namespace clang #endif // COMPILERSUPPORT_H |