diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-02 10:52:18 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-30 08:21:03 +0000 |
commit | 0f922f604297a2022527f04a696da121396ddc0a (patch) | |
tree | 5a40599046ff6ab940aff6d639530237ce08c4d8 /sources/shiboken2/generator/shiboken2 | |
parent | 7af97fa4136d66bbad6c7907de6e7bd823de2e43 (diff) |
Add QStringView/QByteArrayView
View types as function parameters cannot be converted in the standard
way shiboken does it:
QStringView cppArg0;
pythonToCpp(pyArg, &cppArg0);
since they reference some other data.
Introduce a new "viewOn" member to type system entry for them. It
causes the function arguments to be replaced by their viewed-on types
(stringview->string) via metatype.
Add a test in libsample and a test for QUuid::fromString(QStringView).
Test returning QStringView via QRegularExpressionMatch::capturedView().
Task-number: QTBUG-84319
Task-number: PYSIDE-1339
Task-number: PYSIDE-904
Task-number: PYSIDE-487
Change-Id: Iddb4ea268a54928d290e29012e2738772fae83f0
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/generator/shiboken2')
-rw-r--r-- | sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 8e9b480cc..89e97093b 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -2389,6 +2389,8 @@ void CppGenerator::writeTypeCheck(QTextStream &s, const OverloadData *overloadDa // This condition trusts that the OverloadData object will arrange for // PyInt type to come after the more precise numeric types (e.g. float and bool) const AbstractMetaType *argType = overloadData->argType(); + if (auto viewOn = argType->viewOn()) + argType = viewOn; bool numberType = numericTypes.count() == 1 || ShibokenGenerator::isPyInt(argType); QString customType = (overloadData->hasArgumentTypeReplace() ? overloadData->argumentTypeReplaced() : QString()); bool rejectNull = shouldRejectNullPointerArgument(overloadData->referenceFunction(), overloadData->argPos()); @@ -2419,12 +2421,15 @@ const AbstractMetaType *CppGenerator::getArgumentType(const AbstractMetaFunction return nullptr; } - const AbstractMetaType *argType = nullptr; QString typeReplaced = func->typeReplaced(argPos); - if (typeReplaced.isEmpty()) - argType = (argPos == 0) ? func->type() : func->arguments().at(argPos-1)->type(); - else - argType = buildAbstractMetaTypeFromString(typeReplaced); + if (typeReplaced.isEmpty()) { + if (argPos == 0) + return func->type(); + auto argType = func->arguments().at(argPos - 1)->type(); + return argType->viewOn() ? argType->viewOn() : argType; + } + + auto argType = buildAbstractMetaTypeFromString(typeReplaced); if (!argType && !m_knownPythonTypes.contains(typeReplaced)) { qCWarning(lcShiboken).noquote().nospace() << QString::fromLatin1("Unknown type '%1' used as argument type replacement "\ @@ -4804,7 +4809,10 @@ void CppGenerator::writeSignatureInfo(QTextStream &s, const AbstractMetaFunction args << QLatin1String("self"); const AbstractMetaArgumentList &arguments = f->arguments(); for (const AbstractMetaArgument *arg : arguments) { - QString strArg = arg->type()->pythonSignature(); + const auto *metaType = arg->type(); + if (auto viewOn = metaType->viewOn()) + metaType = viewOn; + QString strArg = metaType->pythonSignature(); if (!arg->defaultValueExpression().isEmpty()) { strArg += QLatin1Char('='); QString e = arg->defaultValueExpression(); |