Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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 <qjsondocument.h>
11#include <qjsonarray.h>
12#include <qjsonobject.h>
13#include <qtmocconstants.h>
14#include <qtyperevision.h>
15#include <stdio.h>
16
17#include <private/qtools_p.h>
18
19QT_BEGIN_NAMESPACE
20
21struct QMetaObject;
22
23struct Type
24{
26
27 inline Type() : isVolatile(false), isScoped(false), firstToken(NOTOKEN), referenceType(NoReference) {}
28 inline explicit Type(const QByteArray &_name)
29 : name(_name), rawName(name), isVolatile(false), isScoped(false), firstToken(NOTOKEN), referenceType(NoReference) {}
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
34 uint isVolatile : 1;
35 uint isScoped : 1;
38};
40
41struct ClassDef;
53
55{
56 ArgumentDef() : isDefault(false) {}
59 QByteArray typeNameForCast; // type name to be used in cast from void * in metacall
61
62 QJsonObject toJson() const;
63};
65
67{
74
77 int revision = 0;
78
79 bool isConst = false;
80 bool isVirtual = false;
81 bool isStatic = false;
82 bool inlineCode = false;
83 bool wasCloned = false;
84
86
87 bool isCompat = false;
88 bool isInvokable = false;
89 bool isScriptable = false;
90 bool isSlot = false;
91 bool isSignal = false;
92 bool isPrivateSignal = false;
93 bool isConstructor = false;
94 bool isDestructor = false;
95 bool isAbstract = false;
96 bool isRawSlot = false;
97
98 QJsonObject toJson(int index) const;
99 static void accessToJson(QJsonObject *obj, Access acs);
100};
102
104{
105 bool stdCppSet() const {
106 if (name.isEmpty())
107 return false;
108 QByteArray s("set");
109 s += QtMiscUtils::toAsciiUpper(name[0]);
110 s += name.mid(1);
111 return (s == write);
112 }
113
115 int notifyId = -1; // -1 means no notifyId, >= 0 means signal defined in this class, < -1 means signal not defined in this class
118 int revision = 0;
119 bool constant = false;
120 bool final = false;
121 bool required = false;
122 int relativeIndex = -1; // property index in current metaobject
123
124 qsizetype location = -1; // token index, used for error reporting
125
126 QJsonObject toJson() const;
127};
129
139
146
158
165
201
203 bool hasQNamespace = false;
204 bool doGenerate = false;
205};
207
208class Moc : public Parser
209{
210public:
212
214 : noInclude(false), mustIncludeQPluginH(false), requireCompleteTypes(false)
215 {}
216
218
227 // map from class name to fully qualified name
232
233 void parse();
234 void generate(FILE *out, FILE *jsonOutput);
235
236 bool parseClassHead(ClassDef *def);
237 inline bool inClass(const ClassDef *def) const {
238 return index > def->begin && index < def->end - 1;
239 }
240
241 inline bool inNamespace(const NamespaceDef *def) const {
242 return index > def->begin && index < def->end - 1;
243 }
244
245 const QByteArray &toFullyQualified(const QByteArray &name) const noexcept;
246
247 void prependNamespaces(BaseDef &def, const QList<NamespaceDef> &namespaceList) const;
248
249 Type parseType();
250
251 bool parseEnum(EnumDef *def);
252
253 bool parseFunction(FunctionDef *def, bool inMacro = false);
254 bool parseMaybeFunction(const ClassDef *cdef, FunctionDef *def);
255
256 void parseSlots(ClassDef *def, FunctionDef::Access access);
257 void parseSignals(ClassDef *def);
258 void parseProperty(ClassDef *def, PropertyMode mode);
259 void parsePluginData(ClassDef *def);
260
261 void createPropertyDef(PropertyDef &def, int propertyIndex, PropertyMode mode);
262
265 void parseFlag(BaseDef *def);
268 void parseClassInfo(ClassDef *def);
269 void parseInterfaces(ClassDef *def);
272 void parseMocInclude();
273 void parseSlotInPrivate(ClassDef *def, FunctionDef::Access access);
276
278
280 bool until(Token);
281
282 // test for Q_INVOCABLE, Q_SCRIPTABLE, etc. and set the flags
283 // in FunctionDef accordingly
288
289 bool skipCxxAttributes();
290
291 void checkSuperClasses(ClassDef *def);
292 void checkProperties(ClassDef* cdef);
294
295 void checkListSizes(const ClassDef &def);
296};
297
298inline QByteArray noRef(const QByteArray &type)
299{
300 if (type.endsWith('&')) {
301 if (type.endsWith("&&"))
302 return type.left(type.size()-2);
303 return type.left(type.size()-1);
304 }
305 return type;
306}
307
308QT_END_NAMESPACE
309
310#endif // MOC_H
int main(int argc, char *argv[])
[2]
Definition buffer.cpp:77
Definition moc.h:209
bool testFunctionAttribute(Token tok, FunctionDef *def)
Definition moc.cpp:346
void parseEnumOrFlag(BaseDef *def, QtMocConstants::EnumFlags flags)
Definition moc.cpp:1602
void checkSuperClasses(ClassDef *def)
Definition moc.cpp:1870
Moc()
Definition moc.h:213
void parse()
Definition moc.cpp:664
bool parseEnum(EnumDef *def)
Definition moc.cpp:241
void parseProperty(ClassDef *def, PropertyMode mode)
Definition moc.cpp:1497
QByteArray lexemUntil(Token)
Definition moc.cpp:1770
EncounteredQmlMacro parseClassInfo(BaseDef *def)
Definition moc.cpp:1641
bool until(Token)
Definition moc.cpp:1790
QList< QByteArray > includeFiles
Definition moc.h:223
bool requireCompleteTypes
Definition moc.h:221
QHash< QByteArray, QByteArray > knownQObjectClasses
Definition moc.h:228
void createPropertyDef(PropertyDef &def, int propertyIndex, PropertyMode mode)
Definition moc.cpp:1324
void parseClassInfo(ClassDef *def)
Definition moc.cpp:1668
bool parseClassHead(ClassDef *def)
Definition moc.cpp:39
void parsePrivateProperty(ClassDef *def, PropertyMode mode)
Definition moc.cpp:1589
QByteArray includePath
Definition moc.h:222
QByteArray filename
Definition moc.h:217
void parseFlag(BaseDef *def)
Definition moc.cpp:1617
void parseSignals(ClassDef *def)
Definition moc.cpp:1280
void parseDeclareMetatype()
Definition moc.cpp:1730
void parsePropertyAttributes(PropertyDef &propDef)
Definition moc.cpp:1360
void parseInterfaces(ClassDef *def)
Definition moc.cpp:1674
bool testFunctionRevision(FunctionDef *def)
Definition moc.cpp:409
bool testFunctionAttribute(FunctionDef *def)
Definition moc.cpp:337
void prependNamespaces(BaseDef &def, const QList< NamespaceDef > &namespaceList) const
Definition moc.cpp:618
QHash< QByteArray, QByteArray > knownGadgets
Definition moc.h:229
QList< QByteArray > metaTypes
Definition moc.h:226
bool parseFunction(FunctionDef *def, bool inMacro=false)
Definition moc.cpp:421
QByteArray parsePropertyAccessor()
Definition moc.cpp:1571
QMap< QString, QJsonArray > metaArgs
Definition moc.h:230
bool testForFunctionModifiers(FunctionDef *def)
Definition moc.cpp:523
const QByteArray & toFullyQualified(const QByteArray &name) const noexcept
Definition moc.cpp:30
void parseSlots(ClassDef *def, FunctionDef::Access access)
Definition moc.cpp:1238
void parseDeclareInterface()
Definition moc.cpp:1707
void checkListSizes(const ClassDef &def)
Definition moc.cpp:628
QTypeRevision parseRevision()
Definition moc.cpp:378
void parseMocInclude()
Definition moc.cpp:1739
QList< QString > parsedPluginMetadataFiles
Definition moc.h:231
bool skipCxxAttributes()
Definition moc.cpp:369
PropertyMode
Definition moc.h:211
@ Anonymous
Definition moc.h:211
@ Named
Definition moc.h:211
bool mustIncludeQPluginH
Definition moc.h:220
bool parseMaybeFunction(const ClassDef *cdef, FunctionDef *def)
Definition moc.cpp:531
void checkProperties(ClassDef *cdef)
Definition moc.cpp:1928
Type parseType()
Definition moc.cpp:126
void parseFunctionArguments(FunctionDef *def)
Definition moc.cpp:296
void parseSlotInPrivate(ClassDef *def, FunctionDef::Access access)
Definition moc.cpp:1749
bool inClass(const ClassDef *def) const
Definition moc.h:237
void parsePluginData(ClassDef *def)
Definition moc.cpp:1507
void generate(FILE *out, FILE *jsonOutput)
Definition moc.cpp:1139
QMap< QByteArray, QByteArray > interface2IdMap
Definition moc.h:225
bool noInclude
Definition moc.h:219
EncounteredQmlMacro
Definition moc.h:266
bool inNamespace(const NamespaceDef *def) const
Definition moc.h:241
QList< ClassDef > classList
Definition moc.h:224
int evaluateCondition()
void setDebugIncludes(bool value)
void parseDefineArguments(Macro *m)
void skipUntilEndif()
QHash< QByteArray, QByteArray > nonlocalIncludePathResolutionCache
Symbols preprocessed(const QByteArray &filename, QFile *device)
void substituteUntilNewline(Symbols &substituted)
QList< QByteArray > frameworks
static bool preprocessOnly
static Symbols macroExpandIdentifier(Preprocessor *that, SymbolStack &symbols, int lineNum, QByteArray *macroName)
QByteArray resolveInclude(const QByteArray &filename, const QByteArray &relativeTo)
static Symbols tokenize(const QByteArray &input, int lineNum=1, TokenizeMode mode=TokenizeCpp)
static void macroExpand(Symbols *into, Preprocessor *that, const Symbols &toExpand, qsizetype &index, int lineNum, bool one, const QSet< QByteArray > &excludeSymbols=QSet< QByteArray >())
@ PreparePreprocessorStatement
@ TokenizePreprocessorStatement
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
The QCommandLineParser class provides a means for handling the command line options.
Definition qlist.h:76
\inmodule QtCore
QByteArray unquotedLexem()
Definition symbols.h:102
const Symbol & symbol() const
Definition symbols.h:99
Token token()
Definition symbols.h:100
bool dontReplaceSymbol(const QByteArray &name) const
Definition symbols.h:122
bool hasNext()
Definition symbols.h:86
QByteArray lexem() const
Definition symbols.h:101
Token next()
Definition symbols.h:91
bool test(Token)
Definition symbols.h:108
Q_DECLARE_TYPEINFO(EnumDef, Q_RELOCATABLE_TYPE)
QByteArray noRef(const QByteArray &type)
Definition moc.h:298
Q_DECLARE_TYPEINFO(PropertyDef, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(NamespaceDef, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(ClassDef, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(ClassInfoDef, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(ClassDef::Interface, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(SuperClass, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(ArgumentDef, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(PrivateQPropertyDef, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(Type, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(FunctionDef, Q_RELOCATABLE_TYPE)
Combined button and popup list for selecting options.
QHash< MacroName, Macro > Macros
SubArray MacroName
Token
Definition python.cpp:28
#define qPrintable(string)
Definition qstring.h:1552
static QByteArray combinePath(const QString &infile, const QString &outfile)
Definition main.cpp:40
static bool hasNext(const Symbols &symbols, int i)
Definition main.cpp:78
static const Symbol & next(const Symbols &symbols, int &i)
Definition main.cpp:81
int runMoc(int argc, char **argv)
Definition main.cpp:170
static auto openFileForWriting(const QString &name)
Definition main.cpp:62
void error(const char *msg="Invalid argument")
Definition main.cpp:56
static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments, bool &hasOptionFiles)
Definition main.cpp:138
QByteArray composePreprocessorOutput(const Symbols &symbols)
Definition main.cpp:85
QByteArray rightType
Definition moc.h:58
QByteArray normalizedType
Definition moc.h:58
QJsonObject toJson() const
Definition moc.cpp:2130
QByteArray name
Definition moc.h:58
QByteArray typeNameForCast
Definition moc.h:59
ArgumentDef()
Definition moc.h:56
bool isDefault
Definition moc.h:60
Type type
Definition moc.h:57
Definition moc.h:147
qsizetype end
Definition moc.h:155
qsizetype begin
Definition moc.h:154
QMap< QByteArray, QByteArray > flagAliases
Definition moc.h:153
QByteArray qualified
Definition moc.h:149
qsizetype lineNumber
Definition moc.h:156
QByteArray classname
Definition moc.h:148
QList< ClassInfoDef > classInfoList
Definition moc.h:150
QList< EnumDef > enumList
Definition moc.h:152
Interface(const QByteArray &_className)
Definition moc.h:172
QByteArray className
Definition moc.h:174
QByteArray interfaceId
Definition moc.h:175
QMap< QString, QJsonArray > metaArgs
Definition moc.h:182
QJsonDocument metaData
Definition moc.h:183
QByteArray uri
Definition moc.h:181
QByteArray iid
Definition moc.h:180
bool hasQObject
Definition moc.h:192
QList< QList< Interface > > interfaceList
Definition moc.h:177
QList< FunctionDef > publicList
Definition moc.h:187
QList< FunctionDef > methodList
Definition moc.h:187
QList< PropertyDef > propertyList
Definition moc.h:189
QList< FunctionDef > constructorList
Definition moc.h:186
bool hasQGadget
Definition moc.h:193
QList< SuperClass > superclassList
Definition moc.h:167
bool requireCompleteMethodTypes
Definition moc.h:195
bool hasQNamespace
Definition moc.h:194
QList< FunctionDef > slotList
Definition moc.h:187
QList< FunctionDef > signalList
Definition moc.h:187
int revisionedMethods
Definition moc.h:190
QJsonObject toJson() const
Definition moc.cpp:2003
QList< QByteArray > nonClassSignalList
Definition moc.h:188
QByteArray name
Definition moc.h:142
QByteArray value
Definition moc.h:143
Definition moc.h:43
QByteArray enumName
Definition moc.h:45
QFlags< QtMocConstants::EnumFlags > flags
Definition moc.h:48
QByteArray qualifiedType(const ClassDef *cdef) const
Definition moc.cpp:2205
QJsonObject toJson(const ClassDef &cdef) const
Definition moc.cpp:2184
QList< QByteArray > values
Definition moc.h:47
QByteArray name
Definition moc.h:44
QByteArray type
Definition moc.h:46
bool isVirtual
Definition moc.h:80
bool isScriptable
Definition moc.h:89
bool wasCloned
Definition moc.h:83
QByteArray normalizedType
Definition moc.h:70
QJsonObject toJson(int index) const
Definition moc.cpp:2094
bool isCompat
Definition moc.h:87
bool inlineCode
Definition moc.h:82
Type type
Definition moc.h:68
bool isRawSlot
Definition moc.h:96
static void accessToJson(QJsonObject *obj, Access acs)
Definition moc.cpp:2121
Access access
Definition moc.h:76
bool isSignal
Definition moc.h:91
bool isSlot
Definition moc.h:90
bool isInvokable
Definition moc.h:88
QByteArray name
Definition moc.h:72
QByteArray inPrivateClass
Definition moc.h:73
bool isConst
Definition moc.h:79
QList< ArgumentDef > arguments
Definition moc.h:69
int revision
Definition moc.h:77
bool returnTypeIsVolatile
Definition moc.h:85
bool isAbstract
Definition moc.h:95
bool isPrivateSignal
Definition moc.h:92
bool isDestructor
Definition moc.h:94
@ Public
Definition moc.h:75
@ Protected
Definition moc.h:75
@ Private
Definition moc.h:75
bool isConstructor
Definition moc.h:93
bool isStatic
Definition moc.h:81
QByteArray tag
Definition moc.h:71
Simple structure used by the Doc and DocParser classes.
Symbols symbols
bool isVariadic
bool isFunction
Symbols arguments
bool doGenerate
Definition moc.h:204
bool hasQNamespace
Definition moc.h:203
QByteArray name
Definition moc.h:133
QByteArray storage
Definition moc.h:136
QByteArray accessor
Definition moc.h:135
QByteArray setter
Definition moc.h:134
QByteArray scriptable
Definition moc.h:114
QByteArray member
Definition moc.h:114
QByteArray notify
Definition moc.h:114
QByteArray write
Definition moc.h:114
QByteArray inPrivateClass
Definition moc.h:114
int notifyId
Definition moc.h:115
bool final
Definition moc.h:120
QJsonObject toJson() const
Definition moc.cpp:2139
bool constant
Definition moc.h:119
Specification gspec
Definition moc.h:117
Specification
Definition moc.h:116
@ ReferenceSpec
Definition moc.h:116
@ ValueSpec
Definition moc.h:116
@ PointerSpec
Definition moc.h:116
bool stdCppSet() const
Definition moc.h:105
QByteArray user
Definition moc.h:114
QByteArray read
Definition moc.h:114
qsizetype location
Definition moc.h:124
int revision
Definition moc.h:118
QByteArray bind
Definition moc.h:114
int relativeIndex
Definition moc.h:122
QByteArray designable
Definition moc.h:114
bool required
Definition moc.h:121
QByteArray stored
Definition moc.h:114
QByteArray name
Definition moc.h:114
QByteArray reset
Definition moc.h:114
QByteArray type
Definition moc.h:114
qsizetype index
Definition symbols.h:79
Symbols symbols
Definition symbols.h:76
QByteArray expandedMacro
Definition symbols.h:77
QByteArray array
Definition symbols.h:27
SubArray(const char *s)
Definition symbols.h:22
qsizetype len
Definition symbols.h:29
bool operator==(const SubArray &other) const
Definition symbols.h:30
qsizetype from
Definition symbols.h:28
SubArray()=default
SubArray(const QByteArray &a)
Definition symbols.h:21
SubArray(const QByteArray &a, qsizetype from, qsizetype len)
Definition symbols.h:23
QByteArray qualified
Definition moc.h:161
FunctionDef::Access access
Definition moc.h:162
QByteArray classname
Definition moc.h:160
qsizetype from
Definition symbols.h:68
Symbol(int lineNum, Token token)
Definition symbols.h:49
operator SubArray() const
Definition symbols.h:62
Token token
Definition symbols.h:59
bool operator==(const Symbol &o) const
Definition symbols.h:63
int lineNum
Definition symbols.h:58
Symbol()=default
Symbol(int lineNum, Token token, const QByteArray &lexem, qsizetype from, qsizetype len)
Definition symbols.h:54
QByteArray lexem() const
Definition symbols.h:60
QByteArray lex
Definition symbols.h:67
QByteArray unquotedLexem() const
Definition symbols.h:61
qsizetype len
Definition symbols.h:69
Symbol(int lineNum, Token token, const QByteArray &lexem)
Definition symbols.h:50
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
size_t qHash(const SubArray &key, size_t seed=0)
Definition symbols.h:40
Q_DECLARE_TYPEINFO(Symbol, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(SafeSymbols, Q_RELOCATABLE_TYPE)
QList< Symbol > Symbols
Definition symbols.h:73
#define FOR_ALL_TOKENS(F)
Definition token.h:11
Token PP_Token
Definition token.h:250