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// -- QtScxml
8#include <QtCore/qjsonarray.h>
9#include <QtCore/qjsondocument.h>
10#include <QtCore/qmap.h>
11#include <QtCore/qpair.h>
12#include <QtCore/qtmocconstants.h>
13// -- QtScxml
14
15#include <private/qtools_p.h>
16
17QT_BEGIN_NAMESPACE
18
19struct QMetaObject;
20
21enum class TypeTag : uchar {
22 None,
23 HasStruct = 0x01,
24 HasClass = 0x02,
25 HasEnum = 0x04,
26};
27Q_DECLARE_FLAGS(TypeTags, TypeTag)
28Q_DECLARE_OPERATORS_FOR_FLAGS(TypeTags)
29
30struct Type
31{
32 enum ReferenceType { NoReference, Reference, RValueReference, Pointer };
33
34 inline Type() : isVolatile(false), isScoped(false), /* firstToken(NOTOKEN) -- QtScxml ,*/ referenceType(NoReference) {}
35 inline explicit Type(const QByteArray &_name)
36 : name(_name), rawName(name), isVolatile(false), isScoped(false), /* firstToken(NOTOKEN) -- QtScxml ,*/ referenceType(NoReference) {}
37 QByteArray name;
38 //When used as a return type, the type name may be modified to remove the references.
39 // rawName is the type as found in the function signature
40 QByteArray rawName;
41 uint isVolatile : 1;
42 uint isScoped : 1;
43 TypeTags typeTag;
44#if 0 // -- QtScxml
45 Token firstToken;
46#endif // -- QtScxml
47 ReferenceType referenceType;
48};
49Q_DECLARE_TYPEINFO(Type, Q_RELOCATABLE_TYPE);
50
51struct ClassDef;
52struct EnumDef
53{
54 QByteArray name;
55 QByteArray enumName;
56 QByteArray type;
57 QList<QByteArray> values;
58 QFlags<QtMocConstants::EnumFlags> flags = {};
59 QJsonObject toJson(const ClassDef &cdef) const;
60 QByteArray qualifiedType(const ClassDef *cdef) const;
61};
62Q_DECLARE_TYPEINFO(EnumDef, Q_RELOCATABLE_TYPE);
63
64struct ArgumentDef
65{
66 ArgumentDef() : isDefault(false) {}
67 Type type;
68 QByteArray rightType, normalizedType, name;
69 bool isDefault;
70
71 QJsonObject toJson() const;
72};
73Q_DECLARE_TYPEINFO(ArgumentDef, Q_RELOCATABLE_TYPE);
74
75struct FunctionDef
76{
77 Type type;
78 QList<ArgumentDef> arguments;
79 QByteArray normalizedType;
80 QByteArray tag;
81 QByteArray name;
82 QByteArray inPrivateClass;
83
84 enum Access { Private, Protected, Public };
85 Access access = Private;
86 int revision = 0;
87
88 bool isConst = false;
89 bool isVirtual = false;
90 bool isStatic = false;
91 bool inlineCode = false;
92 bool wasCloned = false;
93
94#if 0 // -- QtScxml
95 bool returnTypeIsVolatile = false;
96#endif // -- QtScxml
97 bool isCompat = false;
98 bool isInvokable = false;
99 bool isScriptable = false;
100 bool isSlot = false;
101 bool isSignal = false;
102 bool isPrivateSignal = false;
103 bool isConstructor = false;
104 bool isDestructor = false;
105 bool isAbstract = false;
106 bool isRawSlot = false;
107
108 QJsonObject toJson(int index) const;
109 static void accessToJson(QJsonObject *obj, Access acs);
110
111// -- QtScxml
112 QByteArray mangledName;
113 const char *implementation = nullptr;
114// -- QtScxml
115};
116Q_DECLARE_TYPEINFO(FunctionDef, Q_RELOCATABLE_TYPE);
117
118struct PropertyDef
119{
120 bool stdCppSet() const {
121 if (name.isEmpty())
122 return false;
123 QByteArray s("set");
124 s += QtMiscUtils::toAsciiUpper(ch: name[0]);
125 s += name.mid(index: 1);
126 return (s == write);
127 }
128
129 QByteArray name, type, member, read, write, bind, reset, designable, scriptable, stored, user, notify, inPrivateClass;
130 int notifyId = -1; // -1 means no notifyId, >= 0 means signal defined in this class, < -1 means signal not defined in this class
131 enum Specification { ValueSpec, ReferenceSpec, PointerSpec };
132 Specification gspec = ValueSpec;
133 int revision = 0;
134 TypeTags typeTag;
135 bool constant = false;
136 bool final = false;
137 bool required = false;
138 int relativeIndex = -1; // property index in current metaobject
139
140 qsizetype location = -1; // token index, used for error reporting
141
142 QJsonObject toJson() const;
143
144// -- QtScxml
145 QByteArray mangledName;
146// -- QtScxml
147};
148Q_DECLARE_TYPEINFO(PropertyDef, Q_RELOCATABLE_TYPE);
149
150struct PrivateQPropertyDef
151{
152 Type type;
153 QByteArray name;
154 QByteArray setter;
155 QByteArray accessor;
156 QByteArray storage;
157};
158Q_DECLARE_TYPEINFO(PrivateQPropertyDef, Q_RELOCATABLE_TYPE);
159
160struct ClassInfoDef
161{
162 QByteArray name;
163 QByteArray value;
164};
165Q_DECLARE_TYPEINFO(ClassInfoDef, Q_RELOCATABLE_TYPE);
166
167struct BaseDef {
168 QByteArray classname;
169 QByteArray qualified;
170 QList<ClassInfoDef> classInfoList;
171 QMap<QByteArray, QFlags<QtMocConstants::EnumFlags>> enumDeclarations;
172 QList<EnumDef> enumList;
173 QMap<QByteArray, QByteArray> flagAliases;
174 qsizetype begin = 0;
175 qsizetype end = 0;
176 qsizetype lineNumber = 0;
177};
178
179struct SuperClass {
180 QByteArray classname;
181 QByteArray qualified;
182 FunctionDef::Access access;
183};
184Q_DECLARE_TYPEINFO(SuperClass, Q_RELOCATABLE_TYPE);
185
186struct ClassDef : BaseDef {
187 QList<SuperClass> superclassList;
188
189 struct Interface
190 {
191 Interface() { } // for QList, don't use
192 inline explicit Interface(const QByteArray &_className)
193 : className(_className) {}
194 QByteArray className;
195 QByteArray interfaceId;
196 };
197 QList<QList<Interface>> interfaceList;
198
199 struct PluginData {
200 QByteArray iid;
201 QByteArray uri;
202 QMap<QString, QJsonArray> metaArgs;
203 QJsonDocument metaData;
204 } pluginData;
205
206 QList<FunctionDef> constructorList;
207 QList<FunctionDef> signalList, slotList, methodList, publicList;
208 QList<QByteArray> nonClassSignalList;
209 QList<PropertyDef> propertyList;
210 QSet<QByteArray> allEnumNames;
211 int revisionedMethods = 0;
212
213 bool hasQObject = false;
214 bool hasQGadget = false;
215 bool hasQNamespace = false;
216 bool requireCompleteMethodTypes = false;
217
218 QJsonObject toJson() const;
219};
220Q_DECLARE_TYPEINFO(ClassDef, Q_RELOCATABLE_TYPE);
221Q_DECLARE_TYPEINFO(ClassDef::Interface, Q_RELOCATABLE_TYPE);
222
223struct NamespaceDef : BaseDef {
224 bool hasQNamespace = false;
225 bool doGenerate = false;
226};
227Q_DECLARE_TYPEINFO(NamespaceDef, Q_RELOCATABLE_TYPE);
228
229#if 0 // -- QtScxml
230class Moc : public Parser
231{
232public:
233 enum PropertyMode { Named, Anonymous };
234
235 Moc()
236 : noInclude(false), mustIncludeQPluginH(false), requireCompleteTypes(false)
237 {}
238
239 QByteArray filename;
240
241 bool noInclude;
242 bool mustIncludeQPluginH;
243 bool requireCompleteTypes;
244 QByteArray includePath;
245 QList<QByteArray> includeFiles;
246 QList<ClassDef> classList;
247 QMap<QByteArray, QByteArray> interface2IdMap;
248 QList<QByteArray> metaTypes;
249 // map from class name to fully qualified name
250 QHash<QByteArray, QByteArray> knownQObjectClasses;
251 QHash<QByteArray, QByteArray> knownGadgets;
252 QMap<QString, QJsonArray> metaArgs;
253 QList<QString> parsedPluginMetadataFiles;
254
255 void parse();
256 QByteArrayView strippedFileName() const;
257 void generate(FILE *out, FILE *jsonOutput);
258
259 bool parseClassHead(ClassDef *def);
260 inline bool inClass(const ClassDef *def) const {
261 return index > def->begin && index < def->end - 1;
262 }
263
264 inline bool inNamespace(const NamespaceDef *def) const {
265 return index > def->begin && index < def->end - 1;
266 }
267
268 const QByteArray &toFullyQualified(const QByteArray &name) const noexcept;
269
270 void prependNamespaces(BaseDef &def, const QList<NamespaceDef> &namespaceList) const;
271
272 Type parseType();
273
274 bool parseEnum(EnumDef *def, ClassDef *containingClass);
275
276 bool parseFunction(FunctionDef *def, bool inMacro = false);
277 bool parseMaybeFunction(const ClassDef *cdef, FunctionDef *def);
278
279 void parseSlots(ClassDef *def, FunctionDef::Access access);
280 void parseSignals(ClassDef *def);
281 void parseProperty(ClassDef *def, PropertyMode mode);
282 void parsePluginData(ClassDef *def);
283
284 void createPropertyDef(PropertyDef &def, int propertyIndex, PropertyMode mode);
285
286 void parsePropertyAttributes(PropertyDef &propDef);
287 void parseEnumOrFlag(BaseDef *def, QtMocConstants::EnumFlags flags);
288 void parseFlag(BaseDef *def);
289 enum class EncounteredQmlMacro {Yes, No};
290 EncounteredQmlMacro parseClassInfo(BaseDef *def);
291 void parseClassInfo(ClassDef *def);
292 void parseInterfaces(ClassDef *def);
293 void parseDeclareInterface();
294 void parseDeclareMetatype();
295 void parseMocInclude();
296 void parseSlotInPrivate(ClassDef *def, FunctionDef::Access access);
297 QByteArray parsePropertyAccessor();
298 void parsePrivateProperty(ClassDef *def, PropertyMode mode);
299
300 void parseFunctionArguments(FunctionDef *def);
301
302 QByteArray lexemUntil(Token);
303 bool until(Token);
304
305 // test for Q_INVOCABLE, Q_SCRIPTABLE, etc. and set the flags
306 // in FunctionDef accordingly
307 bool testFunctionAttribute(FunctionDef *def);
308 bool testFunctionAttribute(Token tok, FunctionDef *def);
309 bool testFunctionRevision(FunctionDef *def);
310 QTypeRevision parseRevision();
311
312 bool skipCxxAttributes();
313
314 void checkSuperClasses(ClassDef *def);
315 void checkProperties(ClassDef* cdef);
316 bool testForFunctionModifiers(FunctionDef *def);
317
318 void checkListSizes(const ClassDef &def);
319};
320#endif // -- QtScxml
321
322inline QByteArray noRef(const QByteArray &type)
323{
324 if (type.endsWith(c: '&')) {
325 if (type.endsWith(bv: "&&"))
326 return type.left(n: type.size()-2);
327 return type.left(n: type.size()-1);
328 }
329 return type;
330}
331
332QT_END_NAMESPACE
333
334#endif // MOC_H
335

source code of qtscxml/tools/qscxmlc/moc.h