|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the tools applications of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef MOC_H |
|
43 #define MOC_H |
|
44 |
|
45 #include "parser.h" |
|
46 #include <QStringList> |
|
47 #include <QMap> |
|
48 #include <QPair> |
|
49 #include <stdio.h> |
|
50 #include <ctype.h> |
|
51 |
|
52 QT_BEGIN_NAMESPACE |
|
53 |
|
54 struct QMetaObject; |
|
55 |
|
56 struct Type |
|
57 { |
|
58 enum ReferenceType { NoReference, Reference, Pointer }; |
|
59 |
|
60 inline Type() : isVolatile(false), isScoped(false), firstToken(NOTOKEN), referenceType(NoReference) {} |
|
61 inline explicit Type(const QByteArray &_name) : name(_name), isVolatile(false), isScoped(false), firstToken(NOTOKEN), referenceType(NoReference) {} |
|
62 QByteArray name; |
|
63 uint isVolatile : 1; |
|
64 uint isScoped : 1; |
|
65 Token firstToken; |
|
66 ReferenceType referenceType; |
|
67 }; |
|
68 |
|
69 struct EnumDef |
|
70 { |
|
71 QByteArray name; |
|
72 QList<QByteArray> values; |
|
73 }; |
|
74 |
|
75 struct ArgumentDef |
|
76 { |
|
77 ArgumentDef() : isDefault(false) {} |
|
78 Type type; |
|
79 QByteArray rightType, normalizedType, name; |
|
80 QByteArray typeNameForCast; // type name to be used in cast from void * in metacall |
|
81 bool isDefault; |
|
82 }; |
|
83 |
|
84 struct FunctionDef |
|
85 { |
|
86 FunctionDef(): returnTypeIsVolatile(false), access(Private), isConst(false), isVirtual(false), |
|
87 inlineCode(false), wasCloned(false), isCompat(false), isInvokable(false), |
|
88 isScriptable(false), isSlot(false), isSignal(false), |
|
89 isConstructor(false), isDestructor(false), isAbstract(false) {} |
|
90 Type type; |
|
91 QByteArray normalizedType; |
|
92 QByteArray tag; |
|
93 QByteArray name; |
|
94 bool returnTypeIsVolatile; |
|
95 |
|
96 QList<ArgumentDef> arguments; |
|
97 |
|
98 enum Access { Private, Protected, Public }; |
|
99 Access access; |
|
100 bool isConst; |
|
101 bool isVirtual; |
|
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 isConstructor; |
|
112 bool isDestructor; |
|
113 bool isAbstract; |
|
114 }; |
|
115 |
|
116 struct PropertyDef |
|
117 { |
|
118 PropertyDef():notifyId(-1), constant(false), final(false), gspec(ValueSpec){} |
|
119 QByteArray name, type, read, write, reset, designable, scriptable, editable, stored, user, notify; |
|
120 int notifyId; |
|
121 bool constant; |
|
122 bool final; |
|
123 enum Specification { ValueSpec, ReferenceSpec, PointerSpec }; |
|
124 Specification gspec; |
|
125 bool stdCppSet() const { |
|
126 QByteArray s("set"); |
|
127 s += toupper(name[0]); |
|
128 s += name.mid(1); |
|
129 return (s == write); |
|
130 } |
|
131 }; |
|
132 |
|
133 |
|
134 struct ClassInfoDef |
|
135 { |
|
136 QByteArray name; |
|
137 QByteArray value; |
|
138 }; |
|
139 |
|
140 struct ClassDef { |
|
141 ClassDef(): |
|
142 hasQObject(false), hasQGadget(false), notifyableProperties(0), begin(0), end(0){} |
|
143 QByteArray classname; |
|
144 QByteArray qualified; |
|
145 QList<QPair<QByteArray, FunctionDef::Access> > superclassList; |
|
146 |
|
147 struct Interface |
|
148 { |
|
149 inline explicit Interface(const QByteArray &_className) |
|
150 : className(_className) {} |
|
151 QByteArray className; |
|
152 QByteArray interfaceId; |
|
153 }; |
|
154 QList<QList<Interface> >interfaceList; |
|
155 |
|
156 bool hasQObject; |
|
157 bool hasQGadget; |
|
158 |
|
159 QList<FunctionDef> constructorList; |
|
160 QList<FunctionDef> signalList, slotList, methodList, publicList; |
|
161 int notifyableProperties; |
|
162 QList<PropertyDef> propertyList; |
|
163 QList<ClassInfoDef> classInfoList; |
|
164 QMap<QByteArray, bool> enumDeclarations; |
|
165 QList<EnumDef> enumList; |
|
166 QMap<QByteArray, QByteArray> flagAliases; |
|
167 |
|
168 int begin; |
|
169 int end; |
|
170 }; |
|
171 |
|
172 struct NamespaceDef { |
|
173 QByteArray name; |
|
174 int begin; |
|
175 int end; |
|
176 }; |
|
177 |
|
178 class Moc : public Parser |
|
179 { |
|
180 public: |
|
181 Moc() |
|
182 : noInclude(false), generatedCode(false), mustIncludeQMetaTypeH(false) |
|
183 {} |
|
184 |
|
185 QByteArray filename; |
|
186 |
|
187 bool noInclude; |
|
188 bool generatedCode; |
|
189 bool mustIncludeQMetaTypeH; |
|
190 QByteArray includePath; |
|
191 QList<QByteArray> includeFiles; |
|
192 QList<ClassDef> classList; |
|
193 QMap<QByteArray, QByteArray> interface2IdMap; |
|
194 QList<QByteArray> metaTypes; |
|
195 QSet<QByteArray> knownQObjectClasses; |
|
196 |
|
197 void parse(); |
|
198 void generate(FILE *out); |
|
199 QList<QMetaObject*> generate(bool ignoreProperties); |
|
200 |
|
201 bool parseClassHead(ClassDef *def); |
|
202 inline bool inClass(const ClassDef *def) const { |
|
203 return index > def->begin && index < def->end - 1; |
|
204 } |
|
205 |
|
206 inline bool inNamespace(const NamespaceDef *def) const { |
|
207 return index > def->begin && index < def->end - 1; |
|
208 } |
|
209 |
|
210 Type parseType(); |
|
211 |
|
212 bool parseEnum(EnumDef *def); |
|
213 |
|
214 bool parseFunction(FunctionDef *def, bool inMacro = false); |
|
215 bool parseMaybeFunction(const ClassDef *cdef, FunctionDef *def); |
|
216 |
|
217 void parseSlots(ClassDef *def, FunctionDef::Access access); |
|
218 void parseSignals(ClassDef *def); |
|
219 void parseProperty(ClassDef *def); |
|
220 void parseEnumOrFlag(ClassDef *def, bool isFlag); |
|
221 void parseFlag(ClassDef *def); |
|
222 void parseClassInfo(ClassDef *def); |
|
223 void parseInterfaces(ClassDef *def); |
|
224 void parseDeclareInterface(); |
|
225 void parseDeclareMetatype(); |
|
226 void parseSlotInPrivate(ClassDef *def, FunctionDef::Access access); |
|
227 |
|
228 void parseFunctionArguments(FunctionDef *def); |
|
229 |
|
230 QByteArray lexemUntil(Token); |
|
231 bool until(Token); |
|
232 |
|
233 // test for Q_INVOCABLE, Q_SCRIPTABLE, etc. and set the flags |
|
234 // in FunctionDef accordingly |
|
235 bool testFunctionAttribute(FunctionDef *def); |
|
236 bool testFunctionAttribute(Token tok, FunctionDef *def); |
|
237 |
|
238 void checkSuperClasses(ClassDef *def); |
|
239 }; |
|
240 |
|
241 inline QByteArray noRef(const QByteArray &type) |
|
242 { |
|
243 if (type.endsWith('&')) |
|
244 return type.left(type.length()-1); |
|
245 return type; |
|
246 } |
|
247 |
|
248 QT_END_NAMESPACE |
|
249 |
|
250 #endif // MOC_H |