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

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