diff options
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 |