diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor/abstractmetatype.h')
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetatype.h | 107 |
1 files changed, 67 insertions, 40 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.h b/sources/shiboken6/ApiExtractor/abstractmetatype.h index 599321262..8a1ecdf20 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.h +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.h @@ -1,40 +1,22 @@ -/**************************************************************************** -** -** 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 ABSTRACTMETATYPE_H #define ABSTRACTMETATYPE_H +#include "abstractmetalang_enums.h" #include "abstractmetalang_typedefs.h" #include "parser/codemodel_enums.h" +#include "typedatabase_typedefs.h" +#include <QtCore/QtCompare> #include <QtCore/qobjectdefs.h> +#include <QtCore/QHashFunctions> #include <QtCore/QSharedDataPointer> #include <QtCore/QList> +#include <QtCore/QSet> + +#include <optional> QT_FORWARD_DECLARE_CLASS(QDebug) @@ -67,11 +49,11 @@ public: Q_ENUM(TypeUsagePattern) AbstractMetaType(); - explicit AbstractMetaType(const TypeEntry *t); + explicit AbstractMetaType(const TypeEntryCPtr &t); AbstractMetaType(const AbstractMetaType &); AbstractMetaType &operator=(const AbstractMetaType &); - AbstractMetaType(AbstractMetaType &&); - AbstractMetaType &operator=(AbstractMetaType &&); + AbstractMetaType(AbstractMetaType &&) noexcept; + AbstractMetaType &operator=(AbstractMetaType &&) noexcept; ~AbstractMetaType(); QString package() const; @@ -87,6 +69,7 @@ public: const AbstractMetaTypeList &instantiations() const; void addInstantiation(const AbstractMetaType &inst); void setInstantiations(const AbstractMetaTypeList &insts); + QStringList instantiationCppSignatures() const; QString minimalSignature() const { return formatSignature(true); } @@ -123,6 +106,7 @@ public: // returns true if the type was used as a smart pointer bool isSmartPointer() const { return typeUsagePattern() == SmartPointerPattern; } + bool isUniquePointer() const; // returns true if the type was used as a flag bool isFlags() const { return typeUsagePattern() == FlagsPattern; } @@ -137,6 +121,7 @@ public: bool passByConstRef() const; bool passByValue() const; + bool useStdMove() const; ReferenceType referenceType() const; void setReferenceType(ReferenceType ref); @@ -160,14 +145,17 @@ public: AbstractMetaTypeList nestedArrayTypes() const; + /// Strip const/indirections/reference from the type + AbstractMetaType plainType() const; + QString cppSignature() const; QString pythonSignature() const; bool applyArrayModification(QString *errorMessage); - const TypeEntry *typeEntry() const; - void setTypeEntry(const TypeEntry *type); + TypeEntryCPtr typeEntry() const; + void setTypeEntry(const TypeEntryCPtr &type); void setOriginalTypeDescription(const QString &otd); QString originalTypeDescription() const; @@ -184,7 +172,8 @@ public: bool hasTemplateChildren() const; - bool equals(const AbstractMetaType &rhs) const; + /// Is equivalent from the POV of argument passing (differ by const ref) + bool isEquivalent(const AbstractMetaType &rhs) const; // View on: Type to use for function argument conversion, fex // std::string_view -> std::string for foo(std::string_view); @@ -194,6 +183,23 @@ public: static AbstractMetaType createVoid(); + /// Builds an AbstractMetaType object from a QString. + /// Returns nullopt if no type could be built from the string. + /// \param typeSignature The string describing the type to be built. + /// \return A new AbstractMetaType object or nullopt in case of failure. + static std::optional<AbstractMetaType> + fromString(const QString &typeSignatureIn, QString *errorMessage = nullptr); + /// Creates an AbstractMetaType object from a TypeEntry. + static AbstractMetaType fromTypeEntry(const TypeEntryCPtr &typeEntry); + /// Creates an AbstractMetaType object from an AbstractMetaClass. + static AbstractMetaType fromAbstractMetaClass(const AbstractMetaClassCPtr &metaClass); + + static void dereference(QString *type); // "foo" -> "(*foo)" + /// Apply the result of shouldDereferenceArgument() + static QString dereferencePrefix(qsizetype n); // Return the prefix **/& as as required + static void applyDereference(QString *type, qsizetype n); + static bool stripDereference(QString *type); // "(*foo)" -> "foo" + // Query functions for generators /// Check if type is a pointer. bool isPointer() const; @@ -214,20 +220,46 @@ public: /// Checks if the type is an Object/QObject or pointer to Value Type. /// In other words, tells if the type is "T*" and T has a Python wrapper. bool isPointerToWrapperType() const; - /// Checks if a meta type should be dereferenced by the Python method wrapper passing it to C++. - bool shouldDereferencePointer() const; + /// Wrapper type passed by reference + bool isWrapperPassedByReference() const; /// Returns true if the type is a C++ integral primitive, /// i.e. bool, char, int, long, and their unsigned counterparts. bool isCppIntegralPrimitive() const; /// 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; + /// Returns whether to generate an opaque container for the type + bool generateOpaqueContainer() const; + /// Returns whether to generate an opaque container for a getter + bool generateOpaqueContainerForGetter(const QString &modifiedType) const; + + /// Types for which libshiboken has built-in primitive converters + static const QSet<QString> &cppFloatTypes(); + static const QSet<QString> &cppSignedCharTypes(); + static const QSet<QString> &cppUnsignedCharTypes(); + static const QSet<QString> &cppCharTypes(); + static const QSet<QString> &cppSignedIntTypes(); + static const QSet<QString> &cppUnsignedIntTypes(); + static const QSet<QString> &cppIntegralTypes(); + static const QSet<QString> &cppPrimitiveTypes(); #ifndef QT_NO_DEBUG_STREAM void formatDebug(QDebug &debug) const; #endif private: + friend size_t qHash(const AbstractMetaType &t, size_t seed = 0) noexcept + { return qHash(t.typeEntry().get(), seed); } + friend bool comparesEqual(const AbstractMetaType &lhs, + const AbstractMetaType &rhs) noexcept; + Q_DECLARE_EQUALITY_COMPARABLE(AbstractMetaType) + friend class AbstractMetaTypeData; QSharedDataPointer<AbstractMetaTypeData> d; @@ -236,11 +268,6 @@ private: QString formatPythonSignature() const; }; -inline bool operator==(const AbstractMetaType &t1, const AbstractMetaType &t2) -{ return t1.equals(t2); } -inline bool operator!=(const AbstractMetaType &t1, const AbstractMetaType &t2) -{ return !t1.equals(t2); } - #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug d, const AbstractMetaType &at); QDebug operator<<(QDebug d, const AbstractMetaType *at); |