diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-12-06 14:47:01 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-12-09 12:37:01 +0000 |
commit | cbf16457aa223154a8e2956a09bca393d5c95242 (patch) | |
tree | 85591388b2c7ffb20cd9802d9ef8593e6bc9955b /sources/shiboken2 | |
parent | 58720761d8b3c22d65d2bee1d064ce55cee62b0f (diff) |
shiboken: Stop using the FinalInCpp attribute for classes
Besides its use for functions, the FinalInCpp attribute was used for
classes meaning something like neither the class nor its derived classes
can be constructed due to presence of private destructors and absence
of non-private constructors. Since 'final' is now a reserved word
in C++ 11, this becomes confusing.
Remove the usage of the attribute for classes, add a bit field indicating
presence of a private constructors and a new function isConstructible() instead.
Change-Id: Ieb2f9943c21511e4f59d228885361e3ad66fb266
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2')
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp | 9 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetalang.cpp | 11 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetalang.h | 24 |
3 files changed, 27 insertions, 17 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index fc990deb7..b7b99bb0a 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -593,7 +593,8 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) << QStringLiteral("class '%1' does not have an entry in the type system") .arg(cls->name()); } else { - const bool couldAddDefaultCtors = !cls->isFinalInCpp() && !cls->isInterface() && !cls->isNamespace() + const bool couldAddDefaultCtors = cls->isConstructible() + && !cls->isInterface() && !cls->isNamespace() && (cls->attributes() & AbstractMetaAttributes::HasRejectedConstructor) == 0; if (couldAddDefaultCtors) { if (!cls->hasConstructors()) @@ -1735,8 +1736,10 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, } const bool isInvalidDestructor = metaFunction->isDestructor() && metaFunction->isPrivate(); - const bool isInvalidConstructor = metaFunction->isConstructor() - && (metaFunction->isPrivate() && metaFunction->functionType() == AbstractMetaFunction::ConstructorFunction); + const bool isInvalidConstructor = metaFunction->functionType() == AbstractMetaFunction::ConstructorFunction + && metaFunction->isPrivate(); + if (isInvalidConstructor) + metaClass->setHasPrivateConstructor(true); if ((isInvalidDestructor || isInvalidConstructor) && !metaClass->hasNonPrivateConstructor()) { *metaClass += AbstractMetaAttributes::Final; diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index f442da5ec..ae71597bd 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -1330,6 +1330,7 @@ AbstractMetaClass::AbstractMetaClass() m_hasNonpublic(false), m_hasVirtualSlots(false), m_hasNonPrivateConstructor(false), + m_hasPrivateConstructor(false), m_functionsFixed(false), m_hasPrivateDestructor(false), m_hasProtectedDestructor(false), @@ -1801,10 +1802,8 @@ bool AbstractMetaClass::hasProtectedMembers() const bool AbstractMetaClass::generateShellClass() const { return m_forceShellClass || - (!isFinal() - && (hasVirtualFunctions() - || hasProtectedFunctions() - || hasFieldAccessors())); + (isConstructible() + && (m_hasVirtuals || hasProtectedFunctions() || hasFieldAccessors())); } QPropertySpec *AbstractMetaClass::propertySpecForRead(const QString &name) const @@ -2595,7 +2594,7 @@ void AbstractMetaClass::fixFunctions() // Make sure class is abstract if one of the functions is if (func->isAbstract()) { (*this) += AbstractMetaAttributes::Abstract; - (*this) -= AbstractMetaAttributes::Final; + (*this) -= AbstractMetaAttributes::FinalInTargetLang; } if (func->isConstructor()) { @@ -2615,7 +2614,7 @@ void AbstractMetaClass::fixFunctions() if (hasPrivateConstructors && !hasPublicConstructors) { (*this) += AbstractMetaAttributes::Abstract; - (*this) -= AbstractMetaAttributes::Final; + (*this) -= AbstractMetaAttributes::FinalInTargetLang; } setFunctions(funcs); diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h index 31d9fa53e..615f8df35 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h @@ -1427,6 +1427,16 @@ public: m_hasNonPrivateConstructor = value; } + bool hasPrivateConstructor() const + { + return m_hasPrivateConstructor; + } + + void setHasPrivateConstructor(bool value) + { + m_hasPrivateConstructor = value; + } + bool hasPrivateDestructor() const { return m_hasPrivateDestructor; @@ -1457,6 +1467,11 @@ public: m_hasVirtualDestructor = value; } + bool isConstructible() const + { + return (hasNonPrivateConstructor() || !hasPrivateConstructor()) && !hasPrivateDestructor(); + } + AbstractMetaFunctionList queryFunctionsByName(const QString &name) const; AbstractMetaFunctionList queryFunctions(FunctionQueryOptions query) const; AbstractMetaFunctionList functionsInTargetLang() const; @@ -1605,14 +1620,6 @@ public: } /** - * Says if a class has any virtual functions of its own. - * \return true if the class implements any virtual methods - */ - bool hasVirtualFunctions() const - { - return !isFinal() && m_hasVirtuals; - } - /** * Says if the class that declares or inherits a virtual function. * \return true if the class implements or inherits any virtual methods */ @@ -1797,6 +1804,7 @@ private: uint m_hasNonpublic : 1; uint m_hasVirtualSlots : 1; uint m_hasNonPrivateConstructor : 1; + uint m_hasPrivateConstructor : 1; uint m_functionsFixed : 1; uint m_hasPrivateDestructor : 1; uint m_hasProtectedDestructor : 1; |