diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-10 14:58:54 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-11 07:57:17 +0200 |
commit | acaa0e5ce430d87eea1d76620e3b9e3584a55f86 (patch) | |
tree | cce83caa766e7d69de3be3bee5990b2b3e79baea /sources/shiboken6/ApiExtractor | |
parent | a4a23da2df6af79f03f0d10bd10a18b3cb437396 (diff) |
shiboken6: Refactor handling of values with copy constructor only
ShibokenGenerato::valueTypeWithCopyConstructorOnly() is frequently
called when writing argument conversions.
Instead of repeatedly searching for classes and looping its functions,
determine the value once in AbstractMetaBuilder and set it as a
boolean flag on class and type entry.
Move the functions from ShibokenGenerator to AbstractMetaType.
Task-number: PYSIDE-1605
Change-Id: If6701ff87b8dd23039f1d35daa6c9291acd0aa87
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/ApiExtractor')
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp | 4 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetalang.cpp | 19 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetalang.h | 2 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetatype.cpp | 16 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetatype.h | 6 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/typesystem.cpp | 14 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/typesystem.h | 4 |
7 files changed, 62 insertions, 3 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp index 43597234b..f9cd7f1d4 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp @@ -506,6 +506,10 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) cls->addDefaultConstructor(); if (cls->canAddDefaultCopyConstructor()) cls->addDefaultCopyConstructor(); + + const bool vco = AbstractMetaClass::determineValueTypeWithCopyConstructorOnly(cls); + cls->setValueTypeWithCopyConstructorOnly(vco); + cls->typeEntry()->setValueTypeWithCopyConstructorOnly(vco); } const auto &allEntries = types->entries(); diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp index 6c4200395..3e42f40ac 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp @@ -71,6 +71,7 @@ public: m_hasCloneOperator(false), m_isTypeDef(false), m_hasToStringCapability(false), + m_valueTypeWithCopyConstructorOnly(false), m_hasCachedWrapper(false) { } @@ -107,6 +108,7 @@ public: uint m_hasCloneOperator : 1; uint m_isTypeDef : 1; uint m_hasToStringCapability : 1; + uint m_valueTypeWithCopyConstructorOnly : 1; mutable uint m_hasCachedWrapper : 1; Documentation m_doc; @@ -1787,11 +1789,22 @@ bool AbstractMetaClass::isCopyable() const bool AbstractMetaClass::isValueTypeWithCopyConstructorOnly() const { - if (!typeEntry()->isValue()) + return d->m_valueTypeWithCopyConstructorOnly; +} + +void AbstractMetaClass::setValueTypeWithCopyConstructorOnly(bool v) +{ + d->m_valueTypeWithCopyConstructorOnly = v; +} + +bool AbstractMetaClass::determineValueTypeWithCopyConstructorOnly(const AbstractMetaClass *c) +{ + + if (!c->typeEntry()->isValue()) return false; - if (attributes().testFlag(AbstractMetaClass::HasRejectedDefaultConstructor)) + if (c->attributes().testFlag(AbstractMetaClass::HasRejectedDefaultConstructor)) return false; - const auto ctors = queryFunctions(FunctionQueryOption::Constructors); + const auto ctors = c->queryFunctions(FunctionQueryOption::Constructors); bool copyConstructorFound = false; for (const auto &ctor : ctors) { switch (ctor->functionType()) { diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.h b/sources/shiboken6/ApiExtractor/abstractmetalang.h index f08ed2039..cc7fd7cec 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken6/ApiExtractor/abstractmetalang.h @@ -348,6 +348,8 @@ public: bool isObjectType() const; bool isCopyable() const; bool isValueTypeWithCopyConstructorOnly() const; + void setValueTypeWithCopyConstructorOnly(bool v); + static bool determineValueTypeWithCopyConstructorOnly(const AbstractMetaClass *c); static AbstractMetaClass *findClass(const AbstractMetaClassList &classes, const QString &name); diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp index dd61421e2..cdec02513 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp @@ -752,6 +752,22 @@ bool AbstractMetaType::isExtendedCppPrimitive() const return d->m_typeEntry->isExtendedCppPrimitive(); } +bool AbstractMetaType::isValueTypeWithCopyConstructorOnly() const +{ + bool result = false; + if (d->m_typeEntry->isComplex()) { + const auto *cte = static_cast<const ComplexTypeEntry *>(d->m_typeEntry); + result = cte->isValueTypeWithCopyConstructorOnly(); + } + return result; +} + +bool AbstractMetaType::valueTypeWithCopyConstructorOnlyPassed() const +{ + return (passByValue() || passByConstRef()) + && isValueTypeWithCopyConstructorOnly(); +} + #ifndef QT_NO_DEBUG_STREAM void AbstractMetaType::formatDebug(QDebug &debug) const { diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.h b/sources/shiboken6/ApiExtractor/abstractmetatype.h index 599321262..4ec4f302c 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.h +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.h @@ -222,6 +222,12 @@ public: /// Returns true if the type is an extended C++ primitive, a void*, /// a const char*, or a std::string (cf isCppPrimitive()). bool isExtendedCppPrimitive() const; + /// Returns whether the underlying type is a value type with copy constructor only + bool isValueTypeWithCopyConstructorOnly() const; + /// Returns whether the type (function argument) is a value type with + /// copy constructor only is passed as value or const-ref and thus + /// no default value can be constructed. + bool valueTypeWithCopyConstructorOnlyPassed() const; #ifndef QT_NO_DEBUG_STREAM void formatDebug(QDebug &debug) const; diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp index d445febfa..80ebdb962 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.cpp +++ b/sources/shiboken6/ApiExtractor/typesystem.cpp @@ -1181,6 +1181,8 @@ public: TypeSystem::SnakeCase m_snakeCase = TypeSystem::SnakeCase::Unspecified; TypeSystem::BoolCast m_operatorBoolMode = TypeSystem::BoolCast::Unspecified; TypeSystem::BoolCast m_isNullMode = TypeSystem::BoolCast::Unspecified; + // Determined by AbstractMetaBuilder from the code model. + bool m_isValueTypeWithCopyConstructorOnly = false; }; ComplexTypeEntry::ComplexTypeEntry(const QString &entryName, TypeEntry::Type t, @@ -1471,6 +1473,18 @@ void ComplexTypeEntry::setSnakeCase(TypeSystem::SnakeCase sc) d->m_snakeCase = sc; } +bool ComplexTypeEntry::isValueTypeWithCopyConstructorOnly() const +{ + S_D(const ComplexTypeEntry); + return d->m_isValueTypeWithCopyConstructorOnly; +} + +void ComplexTypeEntry::setValueTypeWithCopyConstructorOnly(bool v) +{ + S_D(ComplexTypeEntry); + d->m_isValueTypeWithCopyConstructorOnly = v; +} + TypeEntry *ComplexTypeEntry::clone() const { S_D(const ComplexTypeEntry); diff --git a/sources/shiboken6/ApiExtractor/typesystem.h b/sources/shiboken6/ApiExtractor/typesystem.h index fada1fea3..52ad0d435 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.h +++ b/sources/shiboken6/ApiExtractor/typesystem.h @@ -582,6 +582,10 @@ public: TypeSystem::SnakeCase snakeCase() const; void setSnakeCase(TypeSystem::SnakeCase sc); + // Determined by AbstractMetaBuilder from the code model. + bool isValueTypeWithCopyConstructorOnly() const; + void setValueTypeWithCopyConstructorOnly(bool v); + #ifndef QT_NO_DEBUG_STREAM void formatDebug(QDebug &debug) const override; #endif |