1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef MOC_H
30#define MOC_H
31
32#include "parser.h"
33#include <qstringlist.h>
34#include <qmap.h>
35#include <qpair.h>
36#include <qjsondocument.h>
37#include <qjsonarray.h>
38#include <qjsonobject.h>
39#include <stdio.h>
40#include <ctype.h>
41
42QT_BEGIN_NAMESPACE
43
44struct QMetaObject;
45
46struct Type
47{
48 enum ReferenceType { NoReference, Reference, RValueReference, Pointer };
49
50 inline Type() : isVolatile(false), isScoped(false), firstToken(NOTOKEN), referenceType(NoReference) {}
51 inline explicit Type(const QByteArray &_name)
52 : name(_name), rawName(name), isVolatile(false), isScoped(false), firstToken(NOTOKEN), referenceType(NoReference) {}
53 QByteArray name;
54 //When used as a return type, the type name may be modified to remove the references.
55 // rawName is the type as found in the function signature
56 QByteArray rawName;
57 uint isVolatile : 1;
58 uint isScoped : 1;
59 Token firstToken;
60 ReferenceType referenceType;
61};
62Q_DECLARE_TYPEINFO(Type, Q_MOVABLE_TYPE);
63
64struct EnumDef
65{
66 QByteArray name;
67 QList<QByteArray> values;
68 bool isEnumClass; // c++11 enum class
69 EnumDef() : isEnumClass(false) {}
70};
71Q_DECLARE_TYPEINFO(EnumDef, Q_MOVABLE_TYPE);
72
73struct ArgumentDef
74{
75 ArgumentDef() : isDefault(false) {}
76 Type type;
77 QByteArray rightType, normalizedType, name;
78 QByteArray typeNameForCast; // type name to be used in cast from void * in metacall
79 bool isDefault;
80};
81Q_DECLARE_TYPEINFO(ArgumentDef, Q_MOVABLE_TYPE);
82
83struct FunctionDef
84{
85 FunctionDef(): returnTypeIsVolatile(false), access(Private), isConst(false), isVirtual(false), isStatic(false),
86 inlineCode(false), wasCloned(false), isCompat(false), isInvokable(false),
87 isScriptable(false), isSlot(false), isSignal(false), isPrivateSignal(false),
88 isConstructor(false), isDestructor(false), isAbstract(false), revision(0) {}
89 Type type;
90 QByteArray normalizedType;
91 QByteArray tag;
92 QByteArray name;
93 bool returnTypeIsVolatile;
94
95 QVector<ArgumentDef> arguments;
96
97 enum Access { Private, Protected, Public };
98 Access access;
99 bool isConst;
100 bool isVirtual;
101 bool isStatic;
102 bool inlineCode;
103 bool wasCloned;
104
105 QByteArray inPrivateClass;
106 bool isCompat;
107 bool isInvokable;
108 bool isScriptable;
109 bool isSlot;
110 bool isSignal;
111 bool isPrivateSignal;
112 bool isConstructor;
113 bool isDestructor;
114 bool isAbstract;
115
116 int revision;
117};
118Q_DECLARE_TYPEINFO(FunctionDef, Q_MOVABLE_TYPE);
119
120struct PropertyDef
121{
122 PropertyDef():notifyId(-1), constant(false), final(false), gspec(ValueSpec), revision(0){}
123 QByteArray name, type, member, read, write, reset, designable, scriptable, editable, stored, user, notify, inPrivateClass;
124 int notifyId;
125 bool constant;
126 bool final;
127 enum Specification { ValueSpec, ReferenceSpec, PointerSpec };
128 Specification gspec;
129 bool stdCppSet() const {
130 QByteArray s("set");
131 s += toupper(c: name[0]);
132 s += name.mid(index: 1);
133 return (s == write);
134 }
135 int revision;
136};
137Q_DECLARE_TYPEINFO(PropertyDef, Q_MOVABLE_TYPE);
138
139
140struct ClassInfoDef
141{
142 QByteArray name;
143 QByteArray value;
144};
145Q_DECLARE_TYPEINFO(ClassInfoDef, Q_MOVABLE_TYPE);
146
147struct BaseDef {
148 QByteArray classname;
149 QByteArray qualified;
150 QVector<ClassInfoDef> classInfoList;
151 QMap<QByteArray, bool> enumDeclarations;
152 QVector<EnumDef> enumList;
153 QMap<QByteArray, QByteArray> flagAliases;
154 int begin = 0;
155 int end = 0;
156};
157
158struct ClassDef : BaseDef {
159 QVector<QPair<QByteArray, FunctionDef::Access> > superclassList;
160
161 struct Interface
162 {
163 Interface() {} // for QVector, don't use
164 inline explicit Interface(const QByteArray &_className)
165 : className(_className) {}
166 QByteArray className;
167 QByteArray interfaceId;
168 };
169 QVector<QVector<Interface> >interfaceList;
170
171 bool hasQObject = false;
172 bool hasQGadget = false;
173
174 struct PluginData {
175 QByteArray iid;
176 QMap<QString, QJsonArray> metaArgs;
177 QJsonDocument metaData;
178 } pluginData;
179
180 QVector<FunctionDef> constructorList;
181 QVector<FunctionDef> signalList, slotList, methodList, publicList;
182 int notifyableProperties = 0;
183 QVector<PropertyDef> propertyList;
184 int revisionedMethods = 0;
185 int revisionedProperties = 0;
186
187};
188Q_DECLARE_TYPEINFO(ClassDef, Q_MOVABLE_TYPE);
189Q_DECLARE_TYPEINFO(ClassDef::Interface, Q_MOVABLE_TYPE);
190
191struct NamespaceDef : BaseDef {
192 bool hasQNamespace = false;
193};
194Q_DECLARE_TYPEINFO(NamespaceDef, Q_MOVABLE_TYPE);
195
196class Moc : public Parser
197{
198public:
199 Moc()
200 : noInclude(false), mustIncludeQPluginH(false)
201 {}
202
203 QByteArray filename;
204
205 bool noInclude;
206 bool mustIncludeQPluginH;
207 QByteArray includePath;
208 QList<QByteArray> includeFiles;
209 QVector<ClassDef> classList;
210 QMap<QByteArray, QByteArray> interface2IdMap;
211 QList<QByteArray> metaTypes;
212 // map from class name to fully qualified name
213 QHash<QByteArray, QByteArray> knownQObjectClasses;
214 QHash<QByteArray, QByteArray> knownGadgets;
215 QMap<QString, QJsonArray> metaArgs;
216
217 void parse();
218
219 bool parseClassHead(ClassDef *def);
220 inline bool inClass(const ClassDef *def) const {
221 return index > def->begin && index < def->end - 1;
222 }
223
224 inline bool inNamespace(const NamespaceDef *def) const {
225 return index > def->begin && index < def->end - 1;
226 }
227
228 Type parseType();
229
230 bool parseEnum(EnumDef *def);
231
232 bool parseFunction(FunctionDef *def, bool inMacro = false);
233 bool parseMaybeFunction(const ClassDef *cdef, FunctionDef *def);
234
235 void parseSlots(ClassDef *def, FunctionDef::Access access);
236 void parseSignals(ClassDef *def);
237 void parseProperty(ClassDef *def);
238 void parsePluginData(ClassDef *def);
239 void createPropertyDef(PropertyDef &def);
240 void parseEnumOrFlag(BaseDef *def, bool isFlag);
241 void parseFlag(BaseDef *def);
242 void parseClassInfo(BaseDef *def);
243 void parseInterfaces(ClassDef *def);
244 void parseDeclareInterface();
245 void parseDeclareMetatype();
246 void parseSlotInPrivate(ClassDef *def, FunctionDef::Access access);
247 void parsePrivateProperty(ClassDef *def);
248
249 void parseFunctionArguments(FunctionDef *def);
250
251 QByteArray lexemUntil(Token);
252 bool until(Token);
253
254 // test for Q_INVOCABLE, Q_SCRIPTABLE, etc. and set the flags
255 // in FunctionDef accordingly
256 bool testFunctionAttribute(FunctionDef *def);
257 bool testFunctionAttribute(Token tok, FunctionDef *def);
258 bool testFunctionRevision(FunctionDef *def);
259
260 void checkSuperClasses(ClassDef *def);
261 void checkProperties(ClassDef* cdef);
262};
263
264inline QByteArray noRef(const QByteArray &type)
265{
266 if (type.endsWith(c: '&')) {
267 if (type.endsWith(c: "&&"))
268 return type.left(len: type.length()-2);
269 return type.left(len: type.length()-1);
270 }
271 return type;
272}
273
274QT_END_NAMESPACE
275
276#endif // MOC_H
277

source code of qtremoteobjects/tools/repc/moc_copy/moc.h