diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-09-11 08:53:32 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-09-12 06:47:40 +0000 |
commit | 8a62536b1071ac86c86c82089a53b7a4cd172f90 (patch) | |
tree | df595b8c7b750ae7d50b09adb66607da7a4b4709 /sources/shiboken2/generator/shiboken2/shibokengenerator.cpp | |
parent | dbb78237ef6622a2daae32fa3f5fa0cd9b1ffda5 (diff) |
shiboken: Introduce DefaultValue
Introduce a small class storing the return value of
Generator::minimalConstructor() consisting of a type enumeration and a
value, offering formatting for the use cases variable initializations,
return values and constructor arguments lists.
Having distinct formatting for the different use cases has some
advantages:
- Can use nullptr without casts (except in constructor arguments
lists, where the type is needed for disambiguation).
- In the previous implementation using a string, "" indicated an
error; so, it was not possible to use it for default-constructors.
It is now possible to handle default-constructors for
initialization ("Foo f" instead of "Foo f = Foo()".
- Can use {} for return values.
Task-number: PYSIDE-62
Change-Id: I73229cb957d4b92b43de4cdbc3c66703f48faa61
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/generator/shiboken2/shibokengenerator.cpp')
-rw-r--r-- | sources/shiboken2/generator/shiboken2/shibokengenerator.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index 6a7cef6ef..6d263dd01 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -2653,30 +2653,37 @@ QString ShibokenGenerator::getDefaultValue(const AbstractMetaFunction* func, co void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream& s, const AbstractMetaType* type, const QString& defaultCtor) { - if (defaultCtor.isEmpty() && isCppPrimitive(type)) + if (!defaultCtor.isEmpty()) { + s << " = " << defaultCtor; + return; + } + if (isCppPrimitive(type)) return; - QString ctor = defaultCtor.isEmpty() ? minimalConstructor(type) : defaultCtor; - if (ctor.isEmpty()) { + const auto ctor = minimalConstructor(type); + if (ctor.isValid()) { + s << ctor.initialization(); + } else { const QString message = msgCouldNotFindMinimalConstructor(QLatin1String(__FUNCTION__), type->cppSignature()); qCWarning(lcShiboken()).noquote() << message; s << ";\n#error " << message << '\n'; - } else { - s << " = " << ctor; } } void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream& s, const TypeEntry* type, const QString& defaultCtor) { - if (defaultCtor.isEmpty() && isCppPrimitive(type)) + if (!defaultCtor.isEmpty()) { + s << " = " << defaultCtor; + return; + } + if (isCppPrimitive(type)) return; - QString ctor = defaultCtor.isEmpty() ? minimalConstructor(type) : defaultCtor; - - if (ctor.isEmpty()) { + const auto ctor = minimalConstructor(type); + if (ctor.isValid()) { + s << ctor.initialization(); + } else { const QString message = msgCouldNotFindMinimalConstructor(QLatin1String(__FUNCTION__), type->qualifiedCppName()); qCWarning(lcShiboken()).noquote() << message; s << ";\n#error " << message << endl; - } else { - s << " = " << ctor; } } |