diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-02-18 15:22:33 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-02-22 16:07:34 +0100 |
commit | e4c2272dc60e1ff5e2d0933238fe4508af5f7f60 (patch) | |
tree | 3fcf05a347e6c1fc9bc11e95ad99a3fc3be790d6 /sources/shiboken6/ApiExtractor/abstractmetatype.cpp | |
parent | 535a781d534f4c9d102342a9813528e48c576ffd (diff) |
shiboken6: Refactor AbstractMetaType::shouldDereferenceArgument()
Change it to return positive/negative int values indicating the number
of times it should be (de)referenced. This prepares for more
flexibility in arguments handling.
Task-number: PYSIDE-1605
Task-number: PYSIDE-1790
Change-Id: Ib5d2a7685c1d3dd46e3b477af9a89b7d02a80eb2
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/abstractmetatype.cpp')
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetatype.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp index 76bac4363..b48effa56 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp @@ -777,6 +777,17 @@ void AbstractMetaType::dereference(QString *type) type->append(u')'); } +void AbstractMetaType::applyDereference(QString *type, qsizetype n) +{ + if (n == 0) + return; + + const char c = n > 0 ? '*' : '&'; + type->prepend(QString(qAbs(n), QLatin1Char(c))); + type->prepend(u'('); + type->append(u')'); +} + bool AbstractMetaType::stripDereference(QString *type) { if (type->startsWith(u"(*") && type->endsWith(u')')) { @@ -849,15 +860,26 @@ bool AbstractMetaType::isPointerToWrapperType() const bool AbstractMetaType::isWrapperPassedByReference() const { return d->m_referenceType == LValueReference && isWrapperType() - && !isPointer(); + && !isPointer(); } -bool AbstractMetaType::shouldDereferenceArgument() const +qsizetype AbstractMetaType::shouldDereferenceArgument() const { - return isWrapperPassedByReference() - || valueTypeWithCopyConstructorOnlyPassed() - || isObjectTypeUsedAsValueType() - || generateOpaqueContainer(); + if (isWrapperPassedByReference() || valueTypeWithCopyConstructorOnlyPassed() + || isObjectTypeUsedAsValueType()) { + return 1; + } + + if (!d->m_typeEntry->isContainer()) + return 0; + + qsizetype result = -d->m_indirections.size(); + + // For opaque containers, the cppArg in the generated code is a pointer + if (generateOpaqueContainer()) + ++result; + + return result; } bool AbstractMetaType::isCppIntegralPrimitive() const |