aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/tests/dumpcodemodel
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-06-26 10:43:52 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-06-27 09:47:47 +0000
commitd62278afd55c87101de7c7a9327f06cf5326af0b (patch)
tree2d3c20ceccff8220b860f84e8051890a4e79d4ed /sources/shiboken2/tests/dumpcodemodel
parent4a32f9d00b043b7255b590b95e9b35e9de44c4ed (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/tests/dumpcodemodel')
-rw-r--r--sources/shiboken2/tests/dumpcodemodel/main.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/sources/shiboken2/tests/dumpcodemodel/main.cpp b/sources/shiboken2/tests/dumpcodemodel/main.cpp
index 997e13511..e132c97b3 100644
--- a/sources/shiboken2/tests/dumpcodemodel/main.cpp
+++ b/sources/shiboken2/tests/dumpcodemodel/main.cpp
@@ -28,6 +28,7 @@
#include <abstractmetabuilder_p.h>
#include <parser/codemodel.h>
+#include <clangparser/compilersupport.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QCommandLineOption>
@@ -40,6 +41,13 @@
#include <algorithm>
#include <iterator>
+static inline QString languageLevelDescription()
+{
+ return QLatin1String("C++ Language level (c++11..c++17, default=")
+ + QLatin1String(clang::languageLevelOption(clang::emulatedCompilerLanguageLevel()))
+ + QLatin1Char(')');
+}
+
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
@@ -52,6 +60,10 @@ int main(int argc, char **argv)
QCommandLineOption verboseOption(QStringLiteral("d"),
QStringLiteral("Display verbose output about types"));
parser.addOption(verboseOption);
+ QCommandLineOption languageLevelOption(QStringLiteral("std"),
+ languageLevelDescription(),
+ QStringLiteral("level"));
+ parser.addOption(languageLevelOption);
parser.addPositionalArgument(QStringLiteral("file"), QStringLiteral("C++ source file"));
parser.process(app);
@@ -62,7 +74,19 @@ int main(int argc, char **argv)
QByteArrayList arguments;
std::transform(positionalArguments.cbegin(), positionalArguments.cend(),
std::back_inserter(arguments), QFile::encodeName);
- const FileModelItem dom = AbstractMetaBuilderPrivate::buildDom(arguments, 0);
+
+ LanguageLevel level = LanguageLevel::Default;
+ if (parser.isSet(languageLevelOption)) {
+ const QByteArray value = parser.value(languageLevelOption).toLatin1();
+ level = clang::languageLevelFromOption(value.constData());
+ if (level == LanguageLevel::Default) {
+ std::cerr << "Invalid value \"" << value.constData()
+ << "\" for language level option.\n";
+ return -2;
+ }
+ }
+
+ const FileModelItem dom = AbstractMetaBuilderPrivate::buildDom(arguments, level, 0);
if (dom.isNull()) {
QString message = QLatin1String("Unable to parse ") + positionalArguments.join(QLatin1Char(' '));
std::cerr << qPrintable(message) << '\n';