Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
moc.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef MOC_H
5#define MOC_H
6
7#include "parser.h"
8#include <qstringlist.h>
9#include <qmap.h>
10#include <qpair.h>
11#include <qjsondocument.h>
12#include <qjsonarray.h>
13#include <qjsonobject.h>
14#include <qversionnumber.h>
15#include <stdio.h>
16
17#include <private/qtools_p.h>
18
20
21struct QMetaObject;
22
23struct Type
24{
26
28 inline explicit Type(const QByteArray &_name)
31 //When used as a return type, the type name may be modified to remove the references.
32 // rawName is the type as found in the function signature
38};
40
41struct ClassDef;
42struct EnumDef
43{
48 bool isEnumClass; // c++11 enum class
50 QJsonObject toJson(const ClassDef &cdef) const;
51 QByteArray qualifiedType(const ClassDef *cdef) const;
52};
54
56{
60 QByteArray typeNameForCast; // type name to be used in cast from void * in metacall
62
63 QJsonObject toJson() const;
64};
66
68{
75
78 int revision = 0;
79
80 bool isConst = false;
81 bool isVirtual = false;
82 bool isStatic = false;
83 bool inlineCode = false;
84 bool wasCloned = false;
85
87
88 bool isCompat = false;
89 bool isInvokable = false;
90 bool isScriptable = false;
91 bool isSlot = false;
92 bool isSignal = false;
93 bool isPrivateSignal = false;
94 bool isConstructor = false;
95 bool isDestructor = false;
96 bool isAbstract = false;
97 bool isRawSlot = false;
98
99 QJsonObject toJson() const;
100 static void accessToJson(QJsonObject *obj, Access acs);
101};
103
105{
106 bool stdCppSet() const {
107 if (name.isEmpty())
108 return false;
109 QByteArray s("set");
111 s += name.mid(1);
112 return (s == write);
113 }
114
116 int notifyId = -1; // -1 means no notifyId, >= 0 means signal defined in this class, < -1 means signal not defined in this class
119 int revision = 0;
120 bool constant = false;
121 bool final = false;
122 bool required = false;
123 int relativeIndex = -1; // property index in current metaobject
124
125 qsizetype location = -1; // token index, used for error reporting
126
127 QJsonObject toJson() const;
128};
130
132{
138};
140
142{
145};
147
148struct BaseDef {
157};
158
161
163 {
164 Interface() { } // for QList, don't use
165 inline explicit Interface(const QByteArray &_className)
166 : className(_className) {}
169 };
171
172 struct PluginData {
178
184
185 bool hasQObject = false;
186 bool hasQGadget = false;
187 bool hasQNamespace = false;
189
190 QJsonObject toJson() const;
191};
194
196 bool hasQNamespace = false;
197 bool doGenerate = false;
198};
200
201class Moc : public Parser
202{
203public:
205
208 {}
209
211
220 // map from class name to fully qualified name
225
226 void parse();
227 void generate(FILE *out, FILE *jsonOutput);
228
229 bool parseClassHead(ClassDef *def);
230 inline bool inClass(const ClassDef *def) const {
231 return index > def->begin && index < def->end - 1;
232 }
233
234 inline bool inNamespace(const NamespaceDef *def) const {
235 return index > def->begin && index < def->end - 1;
236 }
237
238 void prependNamespaces(BaseDef &def, const QList<NamespaceDef> &namespaceList) const;
239
240 Type parseType();
241
242 bool parseEnum(EnumDef *def);
243
244 bool parseFunction(FunctionDef *def, bool inMacro = false);
245 bool parseMaybeFunction(const ClassDef *cdef, FunctionDef *def);
246
248 void parseSignals(ClassDef *def);
250 void parsePluginData(ClassDef *def);
251
252 void createPropertyDef(PropertyDef &def, int propertyIndex, PropertyMode mode);
253
255 void parseEnumOrFlag(BaseDef *def, bool isFlag);
256 void parseFlag(BaseDef *def);
259 void parseClassInfo(ClassDef *def);
260 void parseInterfaces(ClassDef *def);
263 void parseMocInclude();
267
269
271 bool until(Token);
272
273 // test for Q_INVOCABLE, Q_SCRIPTABLE, etc. and set the flags
274 // in FunctionDef accordingly
279
280 bool skipCxxAttributes();
281
282 void checkSuperClasses(ClassDef *def);
283 void checkProperties(ClassDef* cdef);
285
286 void checkListSizes(const ClassDef &def);
287};
288
290{
291 if (type.endsWith('&')) {
292 if (type.endsWith("&&"))
293 return type.left(type.size()-2);
294 return type.left(type.size()-1);
295 }
296 return type;
297}
298
300
301#endif // MOC_H
Definition moc.h:202
void checkSuperClasses(ClassDef *def)
Definition moc.cpp:1861
Moc()
Definition moc.h:206
void parse()
Definition moc.cpp:658
bool parseEnum(EnumDef *def)
Definition moc.cpp:230
void parseProperty(ClassDef *def, PropertyMode mode)
Definition moc.cpp:1488
QByteArray lexemUntil(Token)
Definition moc.cpp:1761
EncounteredQmlMacro parseClassInfo(BaseDef *def)
Definition moc.cpp:1632
bool until(Token)
Definition moc.cpp:1781
QList< QByteArray > includeFiles
Definition moc.h:216
bool requireCompleteTypes
Definition moc.h:214
QHash< QByteArray, QByteArray > knownQObjectClasses
Definition moc.h:221
void createPropertyDef(PropertyDef &def, int propertyIndex, PropertyMode mode)
Definition moc.cpp:1313
bool parseClassHead(ClassDef *def)
Definition moc.cpp:29
void parsePrivateProperty(ClassDef *def, PropertyMode mode)
Definition moc.cpp:1580
QByteArray includePath
Definition moc.h:215
QByteArray filename
Definition moc.h:210
void parseFlag(BaseDef *def)
Definition moc.cpp:1608
void parseSignals(ClassDef *def)
Definition moc.cpp:1269
void parseDeclareMetatype()
Definition moc.cpp:1721
void parsePropertyAttributes(PropertyDef &propDef)
Definition moc.cpp:1351
void parseInterfaces(ClassDef *def)
Definition moc.cpp:1665
bool testFunctionRevision(FunctionDef *def)
Definition moc.cpp:398
bool testFunctionAttribute(FunctionDef *def)
Definition moc.cpp:326
void prependNamespaces(BaseDef &def, const QList< NamespaceDef > &namespaceList) const
Definition moc.cpp:612
QHash< QByteArray, QByteArray > knownGadgets
Definition moc.h:222
QList< QByteArray > metaTypes
Definition moc.h:219
bool parseFunction(FunctionDef *def, bool inMacro=false)
Definition moc.cpp:410
QByteArray parsePropertyAccessor()
Definition moc.cpp:1562
QMap< QString, QJsonArray > metaArgs
Definition moc.h:223
bool testForFunctionModifiers(FunctionDef *def)
Definition moc.cpp:518
void parseSlots(ClassDef *def, FunctionDef::Access access)
Definition moc.cpp:1227
void parseDeclareInterface()
Definition moc.cpp:1698
void checkListSizes(const ClassDef &def)
Definition moc.cpp:622
QTypeRevision parseRevision()
Definition moc.cpp:367
void parseMocInclude()
Definition moc.cpp:1730
QList< QString > parsedPluginMetadataFiles
Definition moc.h:224
bool skipCxxAttributes()
Definition moc.cpp:358
PropertyMode
Definition moc.h:204
@ Anonymous
Definition moc.h:204
@ Named
Definition moc.h:204
bool mustIncludeQPluginH
Definition moc.h:213
bool parseMaybeFunction(const ClassDef *cdef, FunctionDef *def)
Definition moc.cpp:526
void checkProperties(ClassDef *cdef)
Definition moc.cpp:1919
Type parseType()
Definition moc.cpp:115
void parseFunctionArguments(FunctionDef *def)
Definition moc.cpp:285
void parseSlotInPrivate(ClassDef *def, FunctionDef::Access access)
Definition moc.cpp:1740
bool inClass(const ClassDef *def) const
Definition moc.h:230
void parsePluginData(ClassDef *def)
Definition moc.cpp:1498
void generate(FILE *out, FILE *jsonOutput)
Definition moc.cpp:1129
QMap< QByteArray, QByteArray > interface2IdMap
Definition moc.h:218
bool noInclude
Definition moc.h:212
EncounteredQmlMacro
Definition moc.h:257
bool inNamespace(const NamespaceDef *def) const
Definition moc.h:234
QList< ClassDef > classList
Definition moc.h:217
void parseEnumOrFlag(BaseDef *def, bool isFlag)
Definition moc.cpp:1593
\inmodule QtCore
Definition qbytearray.h:57
QByteArray left(qsizetype len) const
Returns a byte array that contains the first len bytes of this byte array.
\inmodule QtCore
Definition qhash.h:818
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
Definition qjsonobject.h:20
Definition qlist.h:74
Definition qmap.h:186
\inmodule QtCore
QByteArray noRef(const QByteArray &type)
Definition moc.h:289
Combined button and popup list for selecting options.
constexpr char toAsciiUpper(char ch) noexcept
Definition qtools_p.h:92
GLint location
GLenum mode
GLuint index
[2]
GLuint GLuint end
GLenum type
GLenum access
GLuint name
GLhandleARB obj
[2]
GLdouble s
[6]
Definition qopenglext.h:235
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:145
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
ptrdiff_t qsizetype
Definition qtypes.h:70
unsigned int uint
Definition qtypes.h:29
QTextStream out(stdout)
[7]
QByteArray rightType
Definition moc.h:59
QByteArray normalizedType
Definition moc.h:59
QJsonObject toJson() const
Definition moc.cpp:2113
QByteArray name
Definition moc.h:59
QByteArray typeNameForCast
Definition moc.h:60
ArgumentDef()
Definition moc.h:57
bool isDefault
Definition moc.h:61
Type type
Definition moc.h:58
Definition moc.h:148
qsizetype end
Definition moc.h:156
qsizetype begin
Definition moc.h:155
QMap< QByteArray, QByteArray > flagAliases
Definition moc.h:154
QByteArray qualified
Definition moc.h:150
QByteArray classname
Definition moc.h:149
QMap< QByteArray, bool > enumDeclarations
Definition moc.h:152
QList< ClassInfoDef > classInfoList
Definition moc.h:151
QList< EnumDef > enumList
Definition moc.h:153
Interface(const QByteArray &_className)
Definition moc.h:165
QByteArray className
Definition moc.h:167
QByteArray interfaceId
Definition moc.h:168
QMap< QString, QJsonArray > metaArgs
Definition moc.h:175
QJsonDocument metaData
Definition moc.h:176
QByteArray uri
Definition moc.h:174
QByteArray iid
Definition moc.h:173
bool hasQObject
Definition moc.h:185
QList< QList< Interface > > interfaceList
Definition moc.h:170
QList< FunctionDef > publicList
Definition moc.h:180
QList< FunctionDef > methodList
Definition moc.h:180
QList< PropertyDef > propertyList
Definition moc.h:182
QList< FunctionDef > constructorList
Definition moc.h:179
bool hasQGadget
Definition moc.h:186
bool requireCompleteMethodTypes
Definition moc.h:188
QList< QPair< QByteArray, FunctionDef::Access > > superclassList
Definition moc.h:160
bool hasQNamespace
Definition moc.h:187
QList< FunctionDef > slotList
Definition moc.h:180
QList< FunctionDef > signalList
Definition moc.h:180
int revisionedMethods
Definition moc.h:183
struct ClassDef::PluginData pluginData
QJsonObject toJson() const
Definition moc.cpp:1994
QList< QByteArray > nonClassSignalList
Definition moc.h:181
QByteArray name
Definition moc.h:143
QByteArray value
Definition moc.h:144
Definition moc.h:43
bool isEnumClass
Definition moc.h:48
QByteArray enumName
Definition moc.h:45
EnumDef()
Definition moc.h:49
QByteArray qualifiedType(const ClassDef *cdef) const
Definition moc.cpp:2187
QJsonObject toJson(const ClassDef &cdef) const
Definition moc.cpp:2167
QList< QByteArray > values
Definition moc.h:47
QByteArray name
Definition moc.h:44
QByteArray type
Definition moc.h:46
bool isVirtual
Definition moc.h:81
bool isScriptable
Definition moc.h:90
bool wasCloned
Definition moc.h:84
QByteArray normalizedType
Definition moc.h:71
bool isCompat
Definition moc.h:88
QJsonObject toJson() const
Definition moc.cpp:2078
bool inlineCode
Definition moc.h:83
Type type
Definition moc.h:69
bool isRawSlot
Definition moc.h:97
static void accessToJson(QJsonObject *obj, Access acs)
Definition moc.cpp:2104
bool isSignal
Definition moc.h:92
bool isSlot
Definition moc.h:91
bool isInvokable
Definition moc.h:89
QByteArray name
Definition moc.h:73
QByteArray inPrivateClass
Definition moc.h:74
bool isConst
Definition moc.h:80
QList< ArgumentDef > arguments
Definition moc.h:70
int revision
Definition moc.h:78
bool returnTypeIsVolatile
Definition moc.h:86
bool isAbstract
Definition moc.h:96
bool isPrivateSignal
Definition moc.h:93
bool isDestructor
Definition moc.h:95
@ Public
Definition moc.h:76
@ Protected
Definition moc.h:76
@ Private
Definition moc.h:76
bool isConstructor
Definition moc.h:94
bool isStatic
Definition moc.h:82
QByteArray tag
Definition moc.h:72
bool doGenerate
Definition moc.h:197
bool hasQNamespace
Definition moc.h:196
QByteArray name
Definition moc.h:134
QByteArray storage
Definition moc.h:137
QByteArray accessor
Definition moc.h:136
QByteArray setter
Definition moc.h:135
QByteArray scriptable
Definition moc.h:115
QByteArray member
Definition moc.h:115
QByteArray notify
Definition moc.h:115
QByteArray write
Definition moc.h:115
QByteArray inPrivateClass
Definition moc.h:115
int notifyId
Definition moc.h:116
QJsonObject toJson() const
Definition moc.cpp:2122
bool constant
Definition moc.h:120
Specification gspec
Definition moc.h:118
Specification
Definition moc.h:117
@ ReferenceSpec
Definition moc.h:117
@ ValueSpec
Definition moc.h:117
@ PointerSpec
Definition moc.h:117
bool stdCppSet() const
Definition moc.h:106
QByteArray user
Definition moc.h:115
QByteArray read
Definition moc.h:115
int revision
Definition moc.h:119
QByteArray bind
Definition moc.h:115
int relativeIndex
Definition moc.h:123
QByteArray designable
Definition moc.h:115
bool required
Definition moc.h:122
QByteArray stored
Definition moc.h:115
QByteArray name
Definition moc.h:115
QByteArray reset
Definition moc.h:115
QByteArray type
Definition moc.h:115
\inmodule QtCore
Definition moc.h:24
ReferenceType
Definition moc.h:25
@ Reference
Definition moc.h:25
@ Pointer
Definition moc.h:25
@ RValueReference
Definition moc.h:25
@ NoReference
Definition moc.h:25
Type(const QByteArray &_name)
Definition moc.h:28
Token firstToken
Definition moc.h:36
QByteArray rawName
Definition moc.h:33
Type()
Definition moc.h:27
uint isScoped
Definition moc.h:35
uint isVolatile
Definition moc.h:34
QByteArray name
Definition moc.h:30
ReferenceType referenceType
Definition moc.h:37
Token
Definition token.h:194