diff options
Diffstat (limited to 'src/corelib/kernel/qmetaobject_p.h')
-rw-r--r-- | src/corelib/kernel/qmetaobject_p.h | 126 |
1 files changed, 67 insertions, 59 deletions
diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h index d205034d77..d2c36fceb4 100644 --- a/src/corelib/kernel/qmetaobject_p.h +++ b/src/corelib/kernel/qmetaobject_p.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QMETAOBJECT_P_H #define QMETAOBJECT_P_H @@ -59,20 +23,22 @@ #ifndef QT_NO_QOBJECT #include <private/qobject_p.h> // For QObjectPrivate::Connection #endif +#include <private/qtools_p.h> #include <QtCore/qvarlengtharray.h> QT_BEGIN_NAMESPACE -// ### TODO Qt6: add a proper namespace with Q_NAMESPACE and use scoped enums -// A namespace and scoped are needed to avoid enum clashes +// ### TODO - QTBUG-87869: wrap in a proper Q_NAMESPACE and use scoped enums, to avoid name clashes -enum PropertyFlags { +using namespace QtMiscUtils; + +enum PropertyFlags { Invalid = 0x00000000, Readable = 0x00000001, Writable = 0x00000002, Resettable = 0x00000004, EnumOrFlag = 0x00000008, Alias = 0x00000010, - //Reserved for future usage = 0x00000020, + // Reserved for future usage = 0x00000020, StdCppSet = 0x00000100, Constant = 0x00000400, Final = 0x00000800, @@ -84,11 +50,11 @@ enum PropertyFlags { Bindable = 0x02000000 }; -enum MethodFlags { +enum MethodFlags { AccessPrivate = 0x00, AccessProtected = 0x01, AccessPublic = 0x02, - AccessMask = 0x03, //mask + AccessMask = 0x03, // mask MethodMethod = 0x00, MethodSignal = 0x04, @@ -99,14 +65,18 @@ enum MethodFlags { MethodCompatibility = 0x10, MethodCloned = 0x20, MethodScriptable = 0x40, - MethodRevisioned = 0x80 + MethodRevisioned = 0x80, + + MethodIsConst = 0x100, // no use case for volatile so far }; -enum MetaObjectFlags { // keep it in sync with QMetaObjectBuilder::MetaObjectFlag enum +enum MetaObjectFlag { DynamicMetaObject = 0x01, RequiresVariantMetaObject = 0x02, PropertyAccessInStaticMetaCall = 0x04 // since Qt 5.5, property code is in the static metacall }; +Q_DECLARE_FLAGS(MetaObjectFlags, MetaObjectFlag) +Q_DECLARE_OPERATORS_FOR_FLAGS(MetaObjectFlags) enum MetaDataFlags { IsUnresolvedType = 0x80000000, @@ -160,19 +130,54 @@ private: int _type; QByteArray _name; }; -Q_DECLARE_TYPEINFO(QArgumentType, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(QArgumentType, Q_RELOCATABLE_TYPE); typedef QVarLengthArray<QArgumentType, 10> QArgumentTypeArray; -class QMetaMethodPrivate; +namespace { class QMetaMethodPrivate; } +class QMetaMethodInvoker : public QMetaMethod +{ + QMetaMethodInvoker() = delete; + +public: + enum class InvokeFailReason : int { + // negative values mean a match was found but the invocation failed + // (and a warning has been printed) + ReturnTypeMismatch = -1, + DeadLockDetected = -2, + CallViaVirtualFailed = -3, // no warning + ConstructorCallOnObject = -4, + ConstructorCallWithoutResult = -5, + ConstructorCallFailed = -6, // no warning + + CouldNotQueueParameter = -0x1000, + + // zero is success + None = 0, + + // positive values mean the parameters did not match + TooFewArguments, + FormalParameterMismatch = 0x1000, + }; + + // shadows the public function + static InvokeFailReason Q_CORE_EXPORT + invokeImpl(QMetaMethod self, void *target, Qt::ConnectionType, qsizetype paramCount, + const void *const *parameters, const char *const *typeNames, + const QtPrivate::QMetaTypeInterface *const *metaTypes); +}; struct QMetaObjectPrivate { // revision 7 is Qt 5.0 everything lower is not supported // revision 8 is Qt 5.12: It adds the enum name to QMetaEnum // revision 9 is Qt 6.0: It adds the metatype of properties and methods - enum { OutputRevision = 9 }; // Used by moc, qmetaobjectbuilder and qdbus - enum { IntsPerMethod = QMetaMethod::Data::Size}; + // revision 10 is Qt 6.2: The metatype of the metaobject is stored in the metatypes array + // and metamethods store a flag stating whether they are const + // revision 11 is Qt 6.5: The metatype for void is stored in the metatypes array + // revision 12 is Qt 6.6: It adds the metatype for enums + enum { OutputRevision = 12 }; // Used by moc, qmetaobjectbuilder and qdbus + enum { IntsPerMethod = QMetaMethod::Data::Size }; enum { IntsPerEnum = QMetaEnum::Data::Size }; enum { IntsPerProperty = QMetaProperty::Data::Size }; @@ -207,12 +212,18 @@ struct QMetaObjectPrivate int argc, const QArgumentType *types); static int indexOfConstructor(const QMetaObject *m, const QByteArray &name, int argc, const QArgumentType *types); + + enum class Which { Name, Alias }; + static int indexOfEnumerator(const QMetaObject *m, QByteArrayView name, Which which); + static int indexOfEnumerator(const QMetaObject *m, QByteArrayView name); + Q_CORE_EXPORT static QMetaMethod signal(const QMetaObject *m, int signal_index); - static inline int signalOffset(const QMetaObject *m) { + static inline int signalOffset(const QMetaObject *m) + { Q_ASSERT(m != nullptr); int offset = 0; for (m = m->d.superdata; m; m = m->d.superdata) - offset += reinterpret_cast<const QMetaObjectPrivate*>(m->d.data)->signalCount; + offset += reinterpret_cast<const QMetaObjectPrivate *>(m->d.data)->signalCount; return offset; } Q_CORE_EXPORT static int absoluteSignalCount(const QMetaObject *m); @@ -225,7 +236,7 @@ struct QMetaObjectPrivate static QList<QByteArray> parameterTypeNamesFromSignature(const char *signature); #ifndef QT_NO_QOBJECT - //defined in qobject.cpp + // defined in qobject.cpp enum DisconnectType { DisconnectAll, DisconnectOne }; static void memberIndexes(const QObject *obj, const QMetaMethod &member, int *signalIndex, int *methodIndex); @@ -251,6 +262,7 @@ struct QMetaObjectPrivate static bool methodMatch(const QMetaObject *m, const QMetaMethod &method, const QByteArray &name, int argc, const QArgumentType *types); + Q_CORE_EXPORT static QMetaMethod firstMethod(const QMetaObject *baseObject, QByteArrayView name); }; @@ -262,11 +274,7 @@ enum { MetaObjectPrivateFieldCount = sizeof(QMetaObjectPrivate) / sizeof(int) }; // mirrored in moc's utils.h static inline bool is_ident_char(char s) { - return ((s >= 'a' && s <= 'z') - || (s >= 'A' && s <= 'Z') - || (s >= '0' && s <= '9') - || s == '_' - ); + return isAsciiLetterOrNumber(s) || s == '_'; } static inline bool is_space(char s) |