diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor/abstractmetalang.h')
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetalang.h | 181 |
1 files changed, 79 insertions, 102 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.h b/sources/shiboken6/ApiExtractor/abstractmetalang.h index cc7fd7cec..3dc876690 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken6/ApiExtractor/abstractmetalang.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef ABSTRACTMETALANG_H #define ABSTRACTMETALANG_H @@ -32,7 +7,6 @@ #include "abstractmetalang_enums.h" #include "abstractmetalang_typedefs.h" #include "enclosingclassmixin.h" -#include "typesystem_enums.h" #include "typesystem_typedefs.h" #include <QtCore/qobjectdefs.h> @@ -73,7 +47,8 @@ public: HasRejectedDefaultConstructor = 0x00000020, FinalCppClass = 0x00000100, - Deprecated = 0x00000200 + Deprecated = 0x00000200, + Struct = 0x00000400 }; Q_DECLARE_FLAGS(Attributes, Attribute) Q_FLAG(Attribute) @@ -91,11 +66,13 @@ public: ~AbstractMetaClass(); const AbstractMetaFunctionCList &functions() const; + const AbstractMetaFunctionCList &userAddedPythonOverrides() const; void setFunctions(const AbstractMetaFunctionCList &functions); - void addFunction(const AbstractMetaFunctionCPtr &function); + static void addFunction(const AbstractMetaClassPtr &klass, + const AbstractMetaFunctionCPtr &function); bool hasFunction(const QString &str) const; - AbstractMetaFunctionCPtr findFunction(const QString& functionName) const; - AbstractMetaFunctionCList findFunctions(const QString& functionName) const; + AbstractMetaFunctionCPtr findFunction(QAnyStringView functionName) const; + AbstractMetaFunctionCList findFunctions(QAnyStringView functionName) const; AbstractMetaFunctionCPtr findOperatorBool() const; // Find a Qt-style isNull() method suitable for nb_bool AbstractMetaFunctionCPtr findQtIsNullMethod() const; @@ -106,8 +83,8 @@ public: bool hasCopyConstructor() const; bool hasPrivateCopyConstructor() const; - void addDefaultConstructor(); - void addDefaultCopyConstructor(); + static void addDefaultConstructor(const AbstractMetaClassPtr &klass); + static void addDefaultCopyConstructor(const AbstractMetaClassPtr &klass); bool hasNonPrivateConstructor() const; void setHasNonPrivateConstructor(bool value); @@ -138,13 +115,15 @@ public: bool isImplicitlyCopyConstructible() const; bool canAddDefaultCopyConstructor() const; + static void addSynthesizedComparisonOperators(const AbstractMetaClassPtr &c); + bool generateExceptionHandling() const; CppWrapper cppWrapper() const; const UsingMembers &usingMembers() const; void addUsingMember(const UsingMember &um); - bool isUsingMember(const AbstractMetaClass *c, const QString &memberName, + bool isUsingMember(const AbstractMetaClassCPtr &c, const QString &memberName, Access minimumAccess) const; bool hasUsingMemberFor(const QString &memberName) const; @@ -182,7 +161,7 @@ public: void addField(const AbstractMetaField &field); bool hasStaticFields() const; - std::optional<AbstractMetaField> findField(const QString &name) const; + std::optional<AbstractMetaField> findField(QStringView name) const; const AbstractMetaEnumList &enums() const; AbstractMetaEnumList &enums(); @@ -209,42 +188,40 @@ public: QString baseClassName() const; - AbstractMetaClass *defaultSuperclass() const; // Attribute "default-superclass" - void setDefaultSuperclass(AbstractMetaClass *s); + AbstractMetaClassCPtr defaultSuperclass() const; // Attribute "default-superclass" + void setDefaultSuperclass(const AbstractMetaClassPtr &s); - AbstractMetaClass *baseClass() const; - const AbstractMetaClassList &baseClasses() const; + AbstractMetaClassCPtr baseClass() const; + const AbstractMetaClassCList &baseClasses() const; // base classes including defaultSuperclass - AbstractMetaClassList typeSystemBaseClasses() const; + AbstractMetaClassCList typeSystemBaseClasses() const; // Recursive list of all base classes including defaultSuperclass - AbstractMetaClassList allTypeSystemAncestors() const; + AbstractMetaClassCList allTypeSystemAncestors() const; - void addBaseClass(AbstractMetaClass *base_class); - void setBaseClass(AbstractMetaClass *base_class); + void addBaseClass(const AbstractMetaClassCPtr &base_class); + void setBaseClass(const AbstractMetaClassCPtr &base_class); /** * \return the namespace from another package which this namespace extends. */ - const AbstractMetaClass *extendedNamespace() const; - void setExtendedNamespace(const AbstractMetaClass *e); + AbstractMetaClassCPtr extendedNamespace() const; + void setExtendedNamespace(const AbstractMetaClassCPtr &e); - const AbstractMetaClassList &innerClasses() const; - void addInnerClass(AbstractMetaClass* cl); - void setInnerClasses(const AbstractMetaClassList &innerClasses); + const AbstractMetaClassCList &innerClasses() const; + void addInnerClass(const AbstractMetaClassPtr &cl); + void setInnerClasses(const AbstractMetaClassCList &innerClasses); QString package() const; bool isNamespace() const; bool isInvisibleNamespace() const; + bool isInlineNamespace() const; - bool isQObject() const { return inheritsFrom(u"QObject"_qs); } bool isQtNamespace() const; QString qualifiedCppName() const; bool hasSignals() const; - bool inheritsFrom(const AbstractMetaClass *other) const; - bool inheritsFrom(const QString &name) const; /** * Says if the class that declares or inherits a virtual function. @@ -253,60 +230,46 @@ public: bool isPolymorphic() const; /** - * Tells if this class has one or more functions that are protected. - * \return true if the class has protected functions. - */ - bool hasProtectedFunctions() const; - - /** * Tells if this class has one or more fields (member variables) that are protected. * \return true if the class has protected fields. */ bool hasProtectedFields() const; - /** - * Tells if this class has one or more members (functions or fields) that are protected. - * \return true if the class has protected members. - */ - bool hasProtectedMembers() const; - - const TypeEntries &templateArguments() const; - void setTemplateArguments(const TypeEntries &); + const TypeEntryCList &templateArguments() const; + void setTemplateArguments(const TypeEntryCList &); // only valid during metabuilder's run const QStringList &baseClassNames() const; void setBaseClassNames(const QStringList &names); - const ComplexTypeEntry *typeEntry() const; - ComplexTypeEntry *typeEntry(); - void setTypeEntry(ComplexTypeEntry *type); + ComplexTypeEntryCPtr typeEntry() const; + ComplexTypeEntryPtr typeEntry(); + void setTypeEntry(const ComplexTypeEntryPtr &type); - void setHasHashFunction(bool on); + /// Returns the global hash function as found by the code parser + QString hashFunction() const; + void setHashFunction(const QString &); + /// Returns whether the class has a qHash() overload. Currently unused, + /// specified in type system. bool hasHashFunction() const; - bool hasDefaultToStringFunction() const; - - bool hasEqualsOperator() const; - void setHasEqualsOperator(bool on); - - bool hasCloneOperator() const; - void setHasCloneOperator(bool on); - const QList<QPropertySpec> &propertySpecs() const; void addPropertySpec(const QPropertySpec &spec); + void setPropertyDocumentation(const QString &name, const Documentation &doc); // Helpers to search whether a functions is a property setter/getter/reset enum class PropertyFunction { Read, Write, - Reset + Reset, + Notify }; struct PropertyFunctionSearchResult { - int index; + qsizetype index; PropertyFunction function; }; @@ -324,8 +287,8 @@ public: void sortFunctions(); - const AbstractMetaClass *templateBaseClass() const; - void setTemplateBaseClass(const AbstractMetaClass *cls); + AbstractMetaClassCPtr templateBaseClass() const; + void setTemplateBaseClass(const AbstractMetaClassCPtr &cls); bool hasTemplateBaseClassInstantiations() const; const AbstractMetaTypeList &templateBaseClassInstantiations() const; @@ -349,28 +312,27 @@ public: 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); - static const AbstractMetaClass *findClass(const AbstractMetaClassCList &classes, - const QString &name); - static AbstractMetaClass *findClass(const AbstractMetaClassList &classes, - const TypeEntry* typeEntry); - static const AbstractMetaClass *findClass(const AbstractMetaClassCList &classes, - const TypeEntry* typeEntry); - const AbstractMetaClass *findBaseClass(const QString &qualifiedName) const; + static bool determineValueTypeWithCopyConstructorOnly(const AbstractMetaClassCPtr &c, + bool avoidProtectedHack); + + static AbstractMetaClassPtr findClass(const AbstractMetaClassList &classes, + QAnyStringView name); + static AbstractMetaClassCPtr findClass(const AbstractMetaClassCList &classes, + QAnyStringView name); + static AbstractMetaClassPtr findClass(const AbstractMetaClassList &classes, + const TypeEntryCPtr &typeEntry); + static AbstractMetaClassCPtr findClass(const AbstractMetaClassCList &classes, + const TypeEntryCPtr &typeEntry); + AbstractMetaClassCPtr findBaseClass(const QString &qualifiedName) const; static std::optional<AbstractMetaEnumValue> findEnumValue(const AbstractMetaClassList &classes, const QString &string); - static std::optional<AbstractMetaEnum> findEnum(const AbstractMetaClassList &classes, - const EnumTypeEntry *entry); SourceLocation sourceLocation() const; void setSourceLocation(const SourceLocation &sourceLocation); // For AbstractMetaBuilder - void fixFunctions(); + static void fixFunctions(const AbstractMetaClassPtr &klass); bool needsInheritanceSetup() const; void setInheritanceDone(bool b); bool inheritanceDone() const; @@ -382,17 +344,15 @@ private: #ifndef QT_NO_DEBUG_STREAM void format(QDebug &d) const; void formatMembers(QDebug &d) const; + friend QDebug operator<<(QDebug d, const AbstractMetaClassCPtr &ac); + friend QDebug operator<<(QDebug d, const AbstractMetaClassPtr &ac); friend QDebug operator<<(QDebug d, const AbstractMetaClass *ac); + friend void formatMetaClass(QDebug &, const AbstractMetaClass *); #endif QScopedPointer<AbstractMetaClassPrivate> d; }; -inline bool AbstractMetaClass::isFinalInTargetLang() const -{ - return attributes().testFlag(FinalInTargetLang); -} - inline bool AbstractMetaClass::isAbstract() const { return attributes().testFlag(Abstract); @@ -401,7 +361,7 @@ inline bool AbstractMetaClass::isAbstract() const template <class Function> void AbstractMetaClass::invisibleNamespaceRecursion(Function f) const { - for (auto ic : innerClasses()) { + for (const auto &ic : innerClasses()) { if (ic->isInvisibleNamespace()) { f(ic); ic->invisibleNamespaceRecursion(f); @@ -409,6 +369,23 @@ void AbstractMetaClass::invisibleNamespaceRecursion(Function f) const } } +bool inheritsFrom(const AbstractMetaClassCPtr &c, const AbstractMetaClassCPtr &other); +bool inheritsFrom(const AbstractMetaClassCPtr &c, QAnyStringView name); +inline bool isQObject(const AbstractMetaClassCPtr &c) +{ + return inheritsFrom(c, "QObject"); +} + +AbstractMetaClassCPtr findBaseClass(const AbstractMetaClassCPtr &c, + const QString &qualifiedName); + +/// Return type entry of the base class that declares the parent management +TypeEntryCPtr parentManagementEntry(const AbstractMetaClassCPtr &klass); +inline bool hasParentManagement(const AbstractMetaClassCPtr &c) +{ return bool(parentManagementEntry(c)); } + +AbstractMetaClassCList allBaseClasses(const AbstractMetaClassCPtr metaClass); + Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaClass::CppWrapper); Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaClass::Attributes); |