1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of the QtCore module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 3 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
22 ** packaging of this file. Please review the following information to
23 ** ensure the GNU Lesser General Public License version 3 requirements
24 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25 **
26 ** GNU General Public License Usage
27 ** Alternatively, this file may be used under the terms of the GNU
28 ** General Public License version 2.0 or (at your option) the GNU General
29 ** Public license version 3 or any later version approved by the KDE Free
30 ** Qt Foundation. The licenses are as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32 ** included in the packaging of this file. Please review the following
33 ** information to ensure the GNU General Public License requirements will
34 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35 ** https://www.gnu.org/licenses/gpl-3.0.html.
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 #ifndef QMETAOBJECT_P_H
42 #define QMETAOBJECT_P_H
43 
44 //
45 //  W A R N I N G
46 //  -------------
47 //
48 // This file is not part of the Qt API.  It exists for the convenience
49 // of moc.  This header file may change from version to version without notice,
50 // or even be removed.
51 //
52 // We mean it.
53 //
54 
55 #include <QtCore/qglobal.h>
56 #include <QtCore/qobjectdefs.h>
57 #include <QtCore/qmutex.h>
58 #ifndef QT_NO_QOBJECT
59 #include <private/qobject_p.h> // For QObjectPrivate::Connection
60 #endif
61 #include <QtCore/qvarlengtharray.h>
62 
63 QT_BEGIN_NAMESPACE
64 // ### TODO Qt6: add a proper namespace with Q_NAMESPACE and use scoped enums
65 // A namespace and scoped are needed to avoid enum clashes
66 
67 enum PropertyFlags  {
68     Invalid = 0x00000000,
69     Readable = 0x00000001,
70     Writable = 0x00000002,
71     Resettable = 0x00000004,
72     EnumOrFlag = 0x00000008,
73     StdCppSet = 0x00000100,
74 //     Override = 0x00000200,
75     Constant = 0x00000400,
76     Final = 0x00000800,
77     Designable = 0x00001000,
78     ResolveDesignable = 0x00002000,
79     Scriptable = 0x00004000,
80     ResolveScriptable = 0x00008000,
81     Stored = 0x00010000,
82     ResolveStored = 0x00020000,
83     Editable = 0x00040000,
84     ResolveEditable = 0x00080000,
85     User = 0x00100000,
86     ResolveUser = 0x00200000,
87     Notify = 0x00400000,
88     Revisioned = 0x00800000,
89     Required = 0x01000000,
90 };
91 
92 enum MethodFlags  {
93     AccessPrivate = 0x00,
94     AccessProtected = 0x01,
95     AccessPublic = 0x02,
96     AccessMask = 0x03, //mask
97 
98     MethodMethod = 0x00,
99     MethodSignal = 0x04,
100     MethodSlot = 0x08,
101     MethodConstructor = 0x0c,
102     MethodTypeMask = 0x0c,
103 
104     MethodCompatibility = 0x10,
105     MethodCloned = 0x20,
106     MethodScriptable = 0x40,
107     MethodRevisioned = 0x80
108 };
109 
110 enum MetaObjectFlags { // keep it in sync with QMetaObjectBuilder::MetaObjectFlag enum
111     DynamicMetaObject = 0x01,
112     RequiresVariantMetaObject = 0x02,
113     PropertyAccessInStaticMetaCall = 0x04 // since Qt 5.5, property code is in the static metacall
114 };
115 
116 enum MetaDataFlags {
117     IsUnresolvedType = 0x80000000,
118     TypeNameIndexMask = 0x7FFFFFFF,
119     IsUnresolvedSignal = 0x70000000
120 };
121 
122 enum EnumFlags {
123     EnumIsFlag = 0x1,
124     EnumIsScoped = 0x2
125 };
126 
127 extern int qMetaTypeTypeInternal(const char *);
128 
129 class QArgumentType
130 {
131 public:
QArgumentType(int type)132     QArgumentType(int type)
133         : _type(type)
134     {}
QArgumentType(const QByteArray & name)135     QArgumentType(const QByteArray &name)
136         : _type(qMetaTypeTypeInternal(name.constData())), _name(name)
137     {}
QArgumentType()138     QArgumentType()
139         : _type(0)
140     {}
type()141     int type() const
142     { return _type; }
name()143     QByteArray name() const
144     {
145         if (_type && _name.isEmpty())
146             const_cast<QArgumentType *>(this)->_name = QMetaType::typeName(_type);
147         return _name;
148     }
149     bool operator==(const QArgumentType &other) const
150     {
151         if (_type && other._type)
152             return _type == other._type;
153         else
154             return name() == other.name();
155     }
156     bool operator!=(const QArgumentType &other) const
157     {
158         if (_type && other._type)
159             return _type != other._type;
160         else
161             return name() != other.name();
162     }
163 
164 private:
165     int _type;
166     QByteArray _name;
167 };
168 Q_DECLARE_TYPEINFO(QArgumentType, Q_MOVABLE_TYPE);
169 
170 typedef QVarLengthArray<QArgumentType, 10> QArgumentTypeArray;
171 
172 class QMetaMethodPrivate;
173 
174 struct QMetaObjectPrivate
175 {
176     // revision 7 is Qt 5.0 everything lower is not supported
177     // revision 8 is Qt 5.12: It adds the enum name to QMetaEnum
178     enum { OutputRevision = 8 }; // Used by moc, qmetaobjectbuilder and qdbus
179 
180     int revision;
181     int className;
182     int classInfoCount, classInfoData;
183     int methodCount, methodData;
184     int propertyCount, propertyData;
185     int enumeratorCount, enumeratorData;
186     int constructorCount, constructorData;
187     int flags;
188     int signalCount;
189 
getQMetaObjectPrivate190     static inline const QMetaObjectPrivate *get(const QMetaObject *metaobject)
191     { return reinterpret_cast<const QMetaObjectPrivate*>(metaobject->d.data); }
192 
193     static int originalClone(const QMetaObject *obj, int local_method_index);
194 
195     static QByteArray decodeMethodSignature(const char *signature,
196                                             QArgumentTypeArray &types);
197     static int indexOfSignalRelative(const QMetaObject **baseObject,
198                                      const QByteArray &name, int argc,
199                                      const QArgumentType *types);
200     static int indexOfSlotRelative(const QMetaObject **m,
201                                    const QByteArray &name, int argc,
202                                    const QArgumentType *types);
203     static int indexOfSignal(const QMetaObject *m, const QByteArray &name,
204                              int argc, const QArgumentType *types);
205     static int indexOfSlot(const QMetaObject *m, const QByteArray &name,
206                            int argc, const QArgumentType *types);
207     static int indexOfMethod(const QMetaObject *m, const QByteArray &name,
208                              int argc, const QArgumentType *types);
209     static int indexOfConstructor(const QMetaObject *m, const QByteArray &name,
210                                   int argc, const QArgumentType *types);
211     Q_CORE_EXPORT static QMetaMethod signal(const QMetaObject *m, int signal_index);
signalOffsetQMetaObjectPrivate212     static inline int signalOffset(const QMetaObject *m) {
213         Q_ASSERT(m != nullptr);
214         int offset = 0;
215         for (m = m->d.superdata; m; m = m->d.superdata)
216             offset += reinterpret_cast<const QMetaObjectPrivate*>(m->d.data)->signalCount;
217         return offset;
218     }
219     Q_CORE_EXPORT static int absoluteSignalCount(const QMetaObject *m);
220     Q_CORE_EXPORT static int signalIndex(const QMetaMethod &m);
221     static bool checkConnectArgs(int signalArgc, const QArgumentType *signalTypes,
222                                  int methodArgc, const QArgumentType *methodTypes);
223     static bool checkConnectArgs(const QMetaMethodPrivate *signal,
224                                  const QMetaMethodPrivate *method);
225 
226     static QList<QByteArray> parameterTypeNamesFromSignature(const char *signature);
227 
228 #ifndef QT_NO_QOBJECT
229     //defined in qobject.cpp
230     enum DisconnectType { DisconnectAll, DisconnectOne };
231     static void memberIndexes(const QObject *obj, const QMetaMethod &member,
232                               int *signalIndex, int *methodIndex);
233     static QObjectPrivate::Connection *connect(const QObject *sender, int signal_index,
234                         const QMetaObject *smeta,
235                         const QObject *receiver, int method_index_relative,
236                         const QMetaObject *rmeta = nullptr,
237                         int type = 0, int *types = nullptr);
238     static bool disconnect(const QObject *sender, int signal_index,
239                            const QMetaObject *smeta,
240                            const QObject *receiver, int method_index, void **slot,
241                            DisconnectType = DisconnectAll);
242     static inline bool disconnectHelper(QObjectPrivate::ConnectionData *connections, int signalIndex,
243                                         const QObject *receiver, int method_index, void **slot,
244                                         QBasicMutex *senderMutex, DisconnectType = DisconnectAll);
245 #endif
246 };
247 
248 // For meta-object generators
249 
250 enum { MetaObjectPrivateFieldCount = sizeof(QMetaObjectPrivate) / sizeof(int) };
251 
252 #ifndef UTILS_H
253 // mirrored in moc's utils.h
is_ident_char(char s)254 static inline bool is_ident_char(char s)
255 {
256     return ((s >= 'a' && s <= 'z')
257             || (s >= 'A' && s <= 'Z')
258             || (s >= '0' && s <= '9')
259             || s == '_'
260        );
261 }
262 
is_space(char s)263 static inline bool is_space(char s)
264 {
265     return (s == ' ' || s == '\t');
266 }
267 #endif
268 
269 /*
270     This function is shared with moc.cpp. The implementation lives in qmetaobject_moc_p.h, which
271     should be included where needed. The declaration here is not used to avoid warnings from
272     the compiler about unused functions.
273 
274 static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixScope = false, bool adjustConst = true);
275 */
276 
277 QT_END_NAMESPACE
278 
279 #endif
280 
281