From 79c170d8bdafb91da30d17a24d00457f2be478b3 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 10 Apr 2019 12:49:33 +0200 Subject: shiboken: Remove some special handling for QObject's For types, QObjects are equivalent to objects, there is no need to differentiate. Remove the code trying to find whether a type is a QObject. Only AbstractMetaClass needs to know whether it inherits QObject. Add a simple check recursing down the base classes. Change-Id: I2365b451c8873f044b06c09b58aff29e2db3c5b7 Reviewed-by: Cristian Maureira-Fredes --- .../shiboken2/ApiExtractor/abstractmetabuilder.cpp | 68 ---------------------- .../shiboken2/ApiExtractor/abstractmetabuilder_p.h | 3 - .../shiboken2/ApiExtractor/abstractmetalang.cpp | 13 +++-- sources/shiboken2/ApiExtractor/abstractmetalang.h | 7 --- .../ApiExtractor/tests/testabstractmetatype.cpp | 2 - sources/shiboken2/ApiExtractor/typedatabase.cpp | 1 - sources/shiboken2/ApiExtractor/typesystem.cpp | 1 - sources/shiboken2/ApiExtractor/typesystem.h | 10 ---- sources/shiboken2/generator/generator.cpp | 2 +- .../shiboken2/generator/qtdoc/qtdocgenerator.cpp | 2 +- .../shiboken2/generator/shiboken2/cppgenerator.cpp | 1 - .../shiboken2/generator/shiboken2/overloaddata.cpp | 2 +- .../generator/shiboken2/shibokengenerator.cpp | 3 +- 13 files changed, 12 insertions(+), 103 deletions(-) diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index cac96cb43..329e3b079 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -391,27 +391,6 @@ void AbstractMetaBuilderPrivate::traverseStreamOperator(const FunctionModelItem } } -void AbstractMetaBuilderPrivate::fixQObjectForScope(const FileModelItem &dom, - const TypeDatabase *types, - const NamespaceModelItem &scope) -{ - const ClassList &scopeClasses = scope->classes(); - for (const ClassModelItem &item : scopeClasses) { - QString qualifiedName = item->qualifiedName().join(colonColon()); - TypeEntry* entry = types->findType(qualifiedName); - if (entry) { - if (isQObject(dom, qualifiedName) && entry->isComplex()) - static_cast(entry)->setQObject(true); - } - } - - const NamespaceList &namespaces = scope->namespaces(); - for (const NamespaceModelItem &n : namespaces) { - if (scope != n) - fixQObjectForScope(dom, types, n); - } -} - void AbstractMetaBuilderPrivate::sortLists() { for (AbstractMetaClass *cls : qAsConst(m_metaClasses)) @@ -447,9 +426,6 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) pushScope(dom); - // fix up QObject's in the type system.. - fixQObjectForScope(dom, types, dom); - // Start the generation... const ClassList &typeValues = dom->classes(); ReportHandler::setProgressReference(typeValues); @@ -1003,9 +979,6 @@ AbstractMetaClass* AbstractMetaBuilderPrivate::traverseTypeDef(const FileModelIt if (!type) return 0; - if (type->isObject()) - static_cast(type)->setQObject(isQObject(dom, stripTemplateArgs(typeDef->type().qualifiedName().join(colonColon())))); - AbstractMetaClass *metaClass = new AbstractMetaClass; metaClass->setTypeDef(true); metaClass->setTypeEntry(type); @@ -1069,9 +1042,6 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem return 0; } - if (type->isObject()) - ((ObjectTypeEntry*)type)->setQObject(isQObject(dom, fullClassName)); - AbstractMetaClass *metaClass = new AbstractMetaClass; metaClass->setTypeEntry(type); @@ -1438,12 +1408,6 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, .arg(metaFunction->name(), metaClass->name()); } - if (metaFunction->isSignal() && !metaClass->isQObject()) { - qCWarning(lcShiboken).noquote().nospace() - << QStringLiteral("signal '%1' in non-QObject class '%2'") - .arg(metaFunction->name(), metaClass->name()); - } - if (metaFunction->isConversionOperator()) fixReturnTypeOfConversionOperator(metaFunction); @@ -2538,38 +2502,6 @@ QString AbstractMetaBuilderPrivate::fixDefaultValue(const ArgumentModelItem &ite return expr; } -bool AbstractMetaBuilderPrivate::isQObject(const FileModelItem &dom, const QString &qualifiedName) -{ - if (qualifiedName == QLatin1String("QObject")) - return true; - - ClassModelItem classItem = dom->findClass(qualifiedName); - - if (!classItem) { - QStringList names = qualifiedName.split(colonColon()); - NamespaceModelItem ns = dom; - for (int i = 0; i < names.size() - 1 && ns; ++i) - ns = ns->findNamespace(names.at(i)); - if (ns && names.size() >= 2) - classItem = ns->findClass(names.at(names.size() - 1)); - } - - if (!classItem) - return false; - - if (classItem->extendsClass(QLatin1String("QObject"))) - return true; - - const QVector<_ClassModelItem::BaseClass> &baseClasses = classItem->baseClasses(); - for (const _ClassModelItem::BaseClass &baseClass : baseClasses) { - if (isQObject(dom, baseClass.name)) - return true; - } - - return false; -} - - bool AbstractMetaBuilderPrivate::isEnum(const FileModelItem &dom, const QStringList& qualified_name) { CodeModelItem item = dom->model()->findItem(qualified_name, dom); diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h index b0a89324f..ae36af652 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h @@ -158,9 +158,6 @@ public: bool isQObject(const FileModelItem &dom, const QString &qualifiedName); bool isEnum(const FileModelItem &dom, const QStringList &qualifiedName); - void fixQObjectForScope(const FileModelItem &dom, const TypeDatabase *types, - const NamespaceModelItem &item); - void sortLists(); AbstractMetaArgumentList reverseList(const AbstractMetaArgumentList &list); void setInclude(TypeEntry *te, const QString &fileName) const; diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index 95f8048cd..00d2ffb89 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -288,8 +288,7 @@ AbstractMetaType::TypeUsagePattern AbstractMetaType::determineUsagePattern() con if (m_typeEntry->isObject()) { if (indirections() == 0 && m_referenceType == NoReference) return ValuePattern; - return static_cast(m_typeEntry)->isQObject() - ? QObjectPattern : ObjectPattern; + return ObjectPattern; } if (m_typeEntry->isContainer() && indirections() == 0) @@ -322,8 +321,7 @@ void AbstractMetaType::decideUsagePattern() // const-references to pointers can be passed as pointers setReferenceType(NoReference); setConstant(false); - pattern = static_cast(m_typeEntry)->isQObject() - ? QObjectPattern : ObjectPattern; + pattern = ObjectPattern; } setTypeUsagePattern(pattern); } @@ -1636,9 +1634,14 @@ bool AbstractMetaClass::isNamespace() const return m_typeEntry->isNamespace(); } +static bool qObjectPredicate(const AbstractMetaClass *c) +{ + return c->qualifiedCppName() == QLatin1String("QObject"); +} + bool AbstractMetaClass::isQObject() const { - return m_typeEntry->isQObject(); + return qObjectPredicate(this) || recurseClassHierarchy(this, qObjectPredicate) != nullptr; } QString AbstractMetaClass::qualifiedCppName() const diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h index 0c652a39a..4dbae94d2 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h @@ -301,7 +301,6 @@ public: EnumPattern, ValuePattern, ObjectPattern, - QObjectPattern, ValuePointerPattern, NativePointerPattern, NativePointerAsArrayPattern, // "int*" as "int[]" @@ -376,12 +375,6 @@ public: return m_pattern == EnumPattern; } - // returns true if the type is used as a QObject * - bool isQObject() const - { - return m_pattern == QObjectPattern; - } - // returns true if the type is used as an object, e.g. Xxx * bool isObject() const { diff --git a/sources/shiboken2/ApiExtractor/tests/testabstractmetatype.cpp b/sources/shiboken2/ApiExtractor/tests/testabstractmetatype.cpp index fc67ebba5..63434b3a5 100644 --- a/sources/shiboken2/ApiExtractor/tests/testabstractmetatype.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testabstractmetatype.cpp @@ -85,7 +85,6 @@ void TestAbstractMetaType::testConstCharPtrType() QVERIFY(!rtype->isObject()); QVERIFY(!rtype->isPrimitive()); // const char* differs from char, so it's not considered a primitive type by apiextractor QVERIFY(rtype->isNativePointer()); - QVERIFY(!rtype->isQObject()); QCOMPARE(rtype->referenceType(), NoReference); QVERIFY(!rtype->isValue()); QVERIFY(!rtype->isValuePointer()); @@ -159,7 +158,6 @@ void TestAbstractMetaType::testCharType() QVERIFY(!rtype->isObject()); QVERIFY(rtype->isPrimitive()); QVERIFY(!rtype->isNativePointer()); - QVERIFY(!rtype->isQObject()); QCOMPARE(rtype->referenceType(), NoReference); QVERIFY(!rtype->isValue()); QVERIFY(!rtype->isValuePointer()); diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp index 4ce2790f5..c251ce8c3 100644 --- a/sources/shiboken2/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp @@ -802,7 +802,6 @@ void ComplexTypeEntry::formatDebug(QDebug &d) const { TypeEntry::formatDebug(d); FORMAT_NONEMPTY_STRING("targetLangName", m_targetLangName) - FORMAT_BOOL("QObject", m_qobject) FORMAT_BOOL("polymorphicBase", m_polymorphicBase) FORMAT_BOOL("genericClass", m_genericClass) FORMAT_BOOL("deleteInMainThread", m_deleteInMainThread) diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index 3bb2f0efa..c47d3df43 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -3413,7 +3413,6 @@ ComplexTypeEntry::ComplexTypeEntry(const QString &name, TypeEntry::Type t, const QVersionNumber &vr) : TypeEntry(name, t, vr), m_qualifiedCppName(name), - m_qobject(false), m_polymorphicBase(false), m_genericClass(false), m_deleteInMainThread(false) diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h index 1e1b04136..7e6fc191b 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.h +++ b/sources/shiboken2/ApiExtractor/typesystem.h @@ -1284,15 +1284,6 @@ public: return m_fieldMods; } - bool isQObject() const - { - return m_qobject; - } - void setQObject(bool qobject) - { - m_qobject = qobject; - } - QString defaultSuperclass() const { return m_defaultSuperclass; @@ -1410,7 +1401,6 @@ private: QString m_qualifiedCppName; QString m_targetLangName; - uint m_qobject : 1; uint m_polymorphicBase : 1; uint m_genericClass : 1; uint m_deleteInMainThread : 1; diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp index 4b76c2d2c..87758e533 100644 --- a/sources/shiboken2/generator/generator.cpp +++ b/sources/shiboken2/generator/generator.cpp @@ -538,7 +538,7 @@ bool Generator::isObjectType(const TypeEntry* type) } bool Generator::isObjectType(const ComplexTypeEntry* type) { - return type->isObject() || type->isQObject(); + return type->isObject(); } bool Generator::isObjectType(const AbstractMetaClass* metaClass) { diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp index 05729f4b5..6abfde7c9 100644 --- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp @@ -1872,7 +1872,7 @@ QString QtDocGenerator::parseArgDocStyle(const AbstractMetaClass* /* cppClass */ defValue.replace(QLatin1String("::"), QLatin1String(".")); if (defValue == QLatin1String("nullptr")) defValue = none(); - else if (defValue == QLatin1String("0") && (arg->type()->isQObject() || arg->type()->isObject())) + else if (defValue == QLatin1String("0") && arg->type()->isObject()) defValue = none(); } ret += QLatin1Char('=') + defValue; diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 79129d6b8..18a032c25 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -907,7 +907,6 @@ void CppGenerator::writeVirtualMethodNative(QTextStream&s, const AbstractMetaFun QTextStream ac(&argConv); const PrimitiveTypeEntry* argType = (const PrimitiveTypeEntry*) arg->type()->typeEntry(); bool convert = argType->isObject() - || arg->type()->isQObject() || argType->isValue() || arg->type()->isValuePointer() || arg->type()->isNativePointer() diff --git a/sources/shiboken2/generator/shiboken2/overloaddata.cpp b/sources/shiboken2/generator/shiboken2/overloaddata.cpp index 9f0ac51e5..becd66879 100644 --- a/sources/shiboken2/generator/shiboken2/overloaddata.cpp +++ b/sources/shiboken2/generator/shiboken2/overloaddata.cpp @@ -322,7 +322,7 @@ void OverloadData::sortNextOverloads() } // Process inheritance relationships - if (targetType->isValue() || targetType->isObject() || targetType->isQObject()) { + if (targetType->isValue() || targetType->isObject()) { const AbstractMetaClass *metaClass = AbstractMetaClass::findClass(m_generator->classes(), targetType->typeEntry()); const AbstractMetaClassList &ancestors = m_generator->getAllAncestors(metaClass); for (const AbstractMetaClass *ancestor : ancestors) { diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index b5069db14..9328e6ba0 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -729,8 +729,7 @@ QString ShibokenGenerator::getFormatUnitString(const AbstractMetaFunction* func, if (!func->typeReplaced(arg->argumentIndex() + 1).isEmpty()) { result += QLatin1Char(objType); - } else if (arg->type()->isQObject() - || arg->type()->isObject() + } else if (arg->type()->isObject() || arg->type()->isValue() || arg->type()->isValuePointer() || arg->type()->isNativePointer() -- cgit v1.2.3