diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor/abstractmetafunction.h')
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetafunction.h | 173 |
1 files changed, 93 insertions, 80 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.h b/sources/shiboken6/ApiExtractor/abstractmetafunction.h index 20e2e6d90..e252e439d 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.h +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.h @@ -1,42 +1,21 @@ -/**************************************************************************** -** -** 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 ABSTRACTMETAFUNCTION_H #define ABSTRACTMETAFUNCTION_H #include "abstractmetalang_enums.h" #include "abstractmetalang_typedefs.h" -#include "abstractmetaargument.h" #include "typesystem_enums.h" +#include "modifications_typedefs.h" #include "typesystem_typedefs.h" +#include "parser/codemodel_enums.h" +#include <QtCore/QMetaObject> #include <QtCore/QScopedPointer> +#include <optional> + QT_FORWARD_DECLARE_CLASS(QDebug) QT_FORWARD_DECLARE_CLASS(QRegularExpression) @@ -53,6 +32,8 @@ class AbstractMetaFunction { Q_GADGET public: + Q_DISABLE_COPY_MOVE(AbstractMetaFunction) + enum FunctionType { ConstructorFunction, CopyConstructorFunction, @@ -84,6 +65,12 @@ public: }; Q_ENUM(FunctionType) + enum ComparisonOperatorType { + OperatorEqual, OperatorNotEqual, OperatorLess, OperatorLessEqual, + OperatorGreater, OperatorGreaterEqual + }; + Q_ENUM(ComparisonOperatorType) + enum CompareResultFlag { EqualName = 0x00000001, EqualArguments = 0x00000002, @@ -105,29 +92,18 @@ public: enum Attribute { None = 0x00000000, - Friendly = 0x00000001, - - Abstract = 0x00000002, - Static = 0x00000004, ClassMethod = 0x00000008, - FinalInTargetLang = 0x00000010, - GetterFunction = 0x00000020, SetterFunction = 0x00000040, PropertyReader = 0x00000100, PropertyWriter = 0x00000200, PropertyResetter = 0x00000400, + PropertyNotify = 0x00000800, - Invokable = 0x00001000, - - VirtualCppMethod = 0x00010000, - OverriddenCppMethod = 0x00020000, - FinalCppMethod = 0x00040000, // Add by meta builder (implicit constructors, inherited methods, etc) AddedMethod = 0x001000000, - Deprecated = 0x002000000 }; Q_DECLARE_FLAGS(Attributes, Attribute) Q_FLAG(Attribute) @@ -138,17 +114,33 @@ public: void operator+=(Attribute attribute); void operator-=(Attribute attribute); - bool isFinalInTargetLang() const; + FunctionAttributes cppAttributes() const; + void setCppAttributes(FunctionAttributes a); + void setCppAttribute(FunctionAttribute a, bool on = true); + + enum class Flag { // Internal flags not relevant for comparing functions + // Binary operator whose leading/trailing argument was removed by metabuilder + OperatorLeadingClassArgumentRemoved = 0x1, + OperatorTrailingClassArgumentRemoved = 0x2, + OperatorClassArgumentByValue = 0x4, // The removed class argument was passed by value + InheritedFromTemplate = 0x8, // Inherited from a template in metabuilder + HiddenFriend = 0x10, + PrivateSignal = 0x20 // Private Qt signal (cannot emit from client code) + }; + Q_DECLARE_FLAGS(Flags, Flag) + + Flags flags() const; + void setFlags(Flags f); + bool isAbstract() const; bool isClassMethod() const; bool isStatic() const; - bool isInvokable() const; bool isPropertyReader() const; bool isPropertyWriter() const; bool isPropertyResetter() const; - bool isFriendly() const; AbstractMetaFunction(); + explicit AbstractMetaFunction(const QString &name); explicit AbstractMetaFunction(const AddedFunctionPtr &addedFunc); ~AbstractMetaFunction(); @@ -210,9 +202,11 @@ public: bool isArithmeticOperator() const; bool isBitwiseOperator() const; // Includes shift operator bool isComparisonOperator() const; + /// Returns whether this is a comparison accepting owner class + /// (bool operator==(QByteArray,QByteArray) but not bool operator==(QByteArray,const char *) + bool isSymmetricalComparisonOperator() const; bool isIncDecrementOperator() const; bool isLogicalOperator() const; - bool isSubscriptOperator() const; bool isAssignmentOperator() const; // Assignment or move assignment bool isGetter() const; /// Returns whether it is a Qt-style isNull() method suitable for nb_bool @@ -233,12 +227,15 @@ public: QString modifiedName() const; QString minimalSignature() const; + /// List of signatures matched for modifications + QStringList modificationSignatures() const; // Signature with replaced argument types and return type for overload // decisor comment. QString signatureComment() const; QString debugSignature() const; // including virtual/override/final, etc., for debugging only. - bool isModifiedRemoved(const AbstractMetaClass *cls = nullptr) const; + bool isModifiedRemoved(AbstractMetaClassCPtr cls = {}) const; + bool isModifiedFinal(AbstractMetaClassCPtr cls = {}) const; bool isVoid() const; @@ -246,25 +243,27 @@ public: void setType(const AbstractMetaType &type); // The class that has this function as a member. - const AbstractMetaClass *ownerClass() const; - void setOwnerClass(const AbstractMetaClass *cls); + AbstractMetaClassCPtr ownerClass() const; + void setOwnerClass(const AbstractMetaClassCPtr &cls); // Owner excluding invisible namespaces - const AbstractMetaClass *targetLangOwner() const; + AbstractMetaClassCPtr targetLangOwner() const; // The first class in a hierarchy that declares the function - const AbstractMetaClass *declaringClass() const; - void setDeclaringClass(const AbstractMetaClass *cls); + AbstractMetaClassCPtr declaringClass() const; + void setDeclaringClass(const AbstractMetaClassCPtr &cls); // The class that actually implements this function - const AbstractMetaClass *implementingClass() const; - void setImplementingClass(const AbstractMetaClass *cls); + AbstractMetaClassCPtr implementingClass() const; + void setImplementingClass(const AbstractMetaClassCPtr &cls); const AbstractMetaArgumentList &arguments() const; AbstractMetaArgumentList &arguments(); void setArguments(const AbstractMetaArgumentList &arguments); void addArgument(const AbstractMetaArgument &argument); int actualMinimumArgumentCount() const; + // Return the argument index accounting for the isModifiedRemoved arguments [0..n-1] + int actualArgumentIndex(int index) const; bool isDeprecated() const; bool isDestructor() const { return functionType() == DestructorFunction; } @@ -276,40 +275,61 @@ public: bool isSignal() const { return functionType() == SignalFunction; } bool isSlot() const { return functionType() == SlotFunction; } bool isEmptyFunction() const { return functionType() == EmptyFunction; } + bool maybeAccessor() const; FunctionType functionType() const; void setFunctionType(FunctionType type); + std::optional<ComparisonOperatorType> comparisonOperatorType() const; + bool usesRValueReferences() const; bool generateBinding() const; + // Returns whether the function is contained in the positive list of the + // type entry if one is specified. + bool isWhiteListed() const; - QStringList introspectionCompatibleSignatures(const QStringList &resolvedArguments = QStringList()) const; QString signature() const; + /// Return a signature qualified by class name, for error reporting. + QString classQualifiedSignature() const; + + /// Signature with unresolved typedefs as seen by the code parser + QString unresolvedSignature() const; + void setUnresolvedSignature(const QString &); bool isConstant() const; void setConstant(bool constant); /// Returns true if the AbstractMetaFunction was added by the user via the type system description. bool isUserAdded() const; + bool isUserAddedPythonOverride() const; /// Returns true if the AbstractMetaFunction was declared by the user via /// the type system description. bool isUserDeclared() const; CompareResult compareTo(const AbstractMetaFunction *other) const; + bool isConstOverloadOf(const AbstractMetaFunction *other) const; bool operator <(const AbstractMetaFunction &a) const; AbstractMetaFunction *copy() const; QString conversionRule(TypeSystem::Language language, int idx) const; - QList<ReferenceCount> referenceCounts(const AbstractMetaClass *cls, int idx = -2) const; - ArgumentOwner argumentOwner(const AbstractMetaClass *cls, int idx) const; + bool hasConversionRule(TypeSystem::Language language, int idx) const; + QList<ReferenceCount> + referenceCounts(const AbstractMetaClassCPtr &cls, int idx = -2) const; + ArgumentOwner argumentOwner(const AbstractMetaClassCPtr &cls, int idx) const; // Returns the ownership rules for the given argument (target lang). - TypeSystem::Ownership argumentTargetOwnership(const AbstractMetaClass *cls, int idx) const; + TypeSystem::Ownership + argumentTargetOwnership(const AbstractMetaClassCPtr &cls, int idx) const; + + const QString &modifiedTypeName() const; + bool isTypeModified() const { return !modifiedTypeName().isEmpty(); } + bool generateOpaqueContainerReturn() const; - QString typeReplaced(int argument_index) const; bool isModifiedToArray(int argumentIndex) const; + void applyTypeModifications(); + /// Return the (modified) type for the signature; modified-pyi-type, modified-type QString pyiTypeReplaced(int argumentIndex) const; @@ -340,29 +360,32 @@ public: */ bool hasSignatureModifications() const; - const FunctionModificationList &modifications(const AbstractMetaClass *implementor = nullptr) const; + const FunctionModificationList &modifications(AbstractMetaClassCPtr implementor = {}) const; void clearModificationsCache(); + const DocModificationList addedFunctionDocModifications() const; + static FunctionModificationList findClassModifications(const AbstractMetaFunction *f, - const AbstractMetaClass *implementor); + AbstractMetaClassCPtr implementor); static FunctionModificationList findGlobalModifications(const AbstractMetaFunction *f); /** * Return the argument name if there is a modification the renamed value will be returned */ - QString argumentName(int index, bool create = true, const AbstractMetaClass *cl = nullptr) const; + QString argumentName(int index, bool create = true, AbstractMetaClassCPtr cl = {}) const; int propertySpecIndex() const; void setPropertySpecIndex(int i); - FunctionTypeEntry* typeEntry() const; + FunctionTypeEntryPtr typeEntry() const; + void setTypeEntry(const FunctionTypeEntryPtr &typeEntry); - void setTypeEntry(FunctionTypeEntry* typeEntry); + QString targetLangPackage() const; bool isCallOperator() const; static AbstractMetaFunctionCPtr - find(const AbstractMetaFunctionCList &haystack, const QString &needle); + find(const AbstractMetaFunctionCList &haystack, QAnyStringView needle); bool matches(OperatorQueryOptions) const; @@ -408,6 +431,9 @@ public: SourceLocation sourceLocation() const; void setSourceLocation(const SourceLocation &sourceLocation); + static const char *pythonRichCompareOpCode(ComparisonOperatorType ct); + static const char *cppComparisonOperator(ComparisonOperatorType ct); + private: template <class Predicate> bool traverseCodeSnips(Predicate predicate, @@ -418,19 +444,14 @@ private: QScopedPointer<AbstractMetaFunctionPrivate> d; }; -inline bool AbstractMetaFunction::isFinalInTargetLang() const -{ - return attributes().testFlag(FinalInTargetLang); -} - inline bool AbstractMetaFunction::isAbstract() const { - return attributes().testFlag(Abstract); + return cppAttributes().testFlag(FunctionAttribute::Abstract); } inline bool AbstractMetaFunction::isStatic() const { - return attributes().testFlag(Static); + return cppAttributes().testFlag(FunctionAttribute::Static); } inline bool AbstractMetaFunction::isClassMethod() const @@ -438,11 +459,6 @@ inline bool AbstractMetaFunction::isClassMethod() const return attributes().testFlag(ClassMethod); } -inline bool AbstractMetaFunction::isInvokable() const -{ - return attributes().testFlag(Invokable); -} - inline bool AbstractMetaFunction::isPropertyReader() const { return attributes().testFlag(PropertyReader); @@ -458,15 +474,12 @@ inline bool AbstractMetaFunction::isPropertyResetter() const return attributes().testFlag(PropertyResetter); } -inline bool AbstractMetaFunction::isFriendly() const -{ - return attributes().testFlag(Friendly); -} - Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaFunction::CompareResult) Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaFunction::Attributes); +Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaFunction::Flags); + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, const AbstractMetaFunction *af); #endif |