Mercurial > projects > qtd
annotate generator/abstractmetalang.h @ 298:adae77fdc1ea signals
Native QList implementation is now used throughout QtD
author | eldar |
---|---|
date | Sun, 06 Dec 2009 17:26:37 +0000 |
parents | 8627891e4556 |
children | 04b52676b45f |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** | |
5 ** This file is part of Qt Jambi. | |
6 ** | |
7 ** * Commercial Usage | |
8 * Licensees holding valid Qt Commercial licenses may use this file in | |
9 * accordance with the Qt Commercial License Agreement provided with the | |
10 * Software or, alternatively, in accordance with the terms contained in | |
11 * a written agreement between you and Nokia. | |
12 * | |
13 * | |
14 * GNU General Public License Usage | |
15 * Alternatively, this file may be used under the terms of the GNU | |
16 * General Public License versions 2.0 or 3.0 as published by the Free | |
17 * Software Foundation and appearing in the file LICENSE.GPL included in | |
18 * the packaging of this file. Please review the following information | |
19 * to ensure GNU General Public Licensing requirements will be met: | |
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
22 * exception, Nokia gives you certain additional rights. These rights | |
23 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
24 * the file GPL_EXCEPTION.txt in this package. | |
25 * | |
26 * Qt for Windows(R) Licensees | |
27 * As a special exception, Nokia, as the sole copyright holder for Qt | |
28 * Designer, grants users of the Qt/Eclipse Integration plug-in the | |
29 * right for the Qt/Eclipse Integration to link to functionality | |
30 * provided by Qt Designer and its related libraries. | |
31 * | |
32 * | |
33 * If you are unsure which license is appropriate for your use, please | |
34 * contact the sales department at qt-sales@nokia.com. | |
35 | |
36 ** | |
37 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
38 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 #ifndef ABSTRACTMETALANG_H | |
43 #define ABSTRACTMETALANG_H | |
44 | |
45 #include "codemodel.h" | |
46 | |
47 #include "typesystem.h" | |
48 | |
49 #include <QHash> | |
50 #include <QSet> | |
51 #include <QStringList> | |
52 #include <QTextStream> | |
53 | |
54 | |
55 class AbstractMeta; | |
56 class AbstractMetaClass; | |
57 class AbstractMetaField; | |
58 class AbstractMetaFunction; | |
59 class AbstractMetaType; | |
60 class AbstractMetaVariable; | |
61 class AbstractMetaArgument; | |
62 class AbstractMetaEnumValue; | |
63 class AbstractMetaEnum; | |
64 class QPropertySpec; | |
65 | |
66 typedef QList<AbstractMetaField *> AbstractMetaFieldList; | |
67 typedef QList<AbstractMetaArgument *> AbstractMetaArgumentList; | |
68 typedef QList<AbstractMetaFunction *> AbstractMetaFunctionList; | |
69 class AbstractMetaClassList : public QList<AbstractMetaClass *> | |
70 { | |
71 public: | |
72 AbstractMetaClass *findClass(const QString &name) const; | |
73 AbstractMetaEnumValue *findEnumValue(const QString &string) const; | |
74 AbstractMetaEnum *findEnum(const EnumTypeEntry *entry) const; | |
75 | |
76 }; | |
77 | |
78 | |
79 | |
80 class AbstractMetaAttributes | |
81 { | |
82 public: | |
83 AbstractMetaAttributes() : m_attributes(0) { }; | |
84 | |
85 enum Attribute { | |
86 None = 0x00000000, | |
87 | |
88 Private = 0x00000001, | |
89 Protected = 0x00000002, | |
90 Public = 0x00000004, | |
91 Friendly = 0x00000008, | |
92 Visibility = 0x0000000f, | |
93 | |
94 Native = 0x00000010, | |
95 Abstract = 0x00000020, | |
96 Static = 0x00000040, | |
97 | |
98 FinalInTargetLang = 0x00000080, | |
99 FinalInCpp = 0x00000100, | |
100 ForceShellImplementation = 0x00000200, | |
101 | |
102 GetterFunction = 0x00000400, | |
103 SetterFunction = 0x00000800, | |
104 | |
105 FinalOverload = 0x00001000, | |
106 InterfaceFunction = 0x00002000, | |
107 | |
108 PropertyReader = 0x00004000, | |
109 PropertyWriter = 0x00008000, | |
110 PropertyResetter = 0x00010000, | |
111 | |
112 Fake = 0x00020000, | |
113 | |
114 Invokable = 0x00040000, | |
115 | |
116 Final = FinalInTargetLang | FinalInCpp | |
117 }; | |
118 | |
119 uint attributes() const { return m_attributes; } | |
120 void setAttributes(uint attributes) { m_attributes = attributes; } | |
121 | |
122 uint originalAttributes() const { return m_originalAttributes; } | |
123 void setOriginalAttributes(uint attributes) { m_originalAttributes = attributes; } | |
124 | |
125 uint visibility() const { return m_attributes & Visibility; } | |
126 void setVisibility(uint visi) { m_attributes = (m_attributes & ~Visibility) | visi; } | |
127 | |
128 void operator+=(Attribute attribute) { m_attributes |= attribute; } | |
129 void operator-=(Attribute attribute) { m_attributes &= ~attribute; } | |
130 | |
131 bool isNative() const { return m_attributes & Native; } | |
132 bool isFinal() const { return (m_attributes & Final) == Final; } | |
133 bool isFinalInTargetLang() const { return m_attributes & FinalInTargetLang; } | |
134 bool isFinalInCpp() const { return m_attributes & FinalInCpp; } | |
135 bool isAbstract() const { return m_attributes & Abstract; } | |
136 bool isStatic() const { return m_attributes & Static; } | |
137 bool isForcedShellImplementation() const { return m_attributes & ForceShellImplementation; } | |
138 bool isInterfaceFunction() const { return m_attributes & InterfaceFunction; } | |
139 bool isFinalOverload() const { return m_attributes & FinalOverload; } | |
140 bool isInvokable() const { return m_attributes & Invokable; } | |
141 | |
142 bool isPropertyReader() const { return m_attributes & PropertyReader; } | |
143 bool isPropertyWriter() const { return m_attributes & PropertyWriter; } | |
144 bool isPropertyResetter() const { return m_attributes & PropertyResetter; } | |
145 | |
146 bool isPrivate() const { return m_attributes & Private; } | |
147 bool isProtected() const { return m_attributes & Protected; } | |
148 bool isPublic() const { return m_attributes & Public; } | |
149 bool isFriendly() const { return m_attributes & Friendly; } | |
150 | |
151 bool wasPrivate() const { return m_originalAttributes & Private; } | |
152 bool wasProtected() const { return m_originalAttributes & Protected; } | |
153 bool wasPublic() const { return m_originalAttributes & Public; } | |
154 bool wasFriendly() const { return m_originalAttributes & Friendly; } | |
155 | |
156 private: | |
157 uint m_attributes; | |
158 uint m_originalAttributes; | |
159 }; | |
160 | |
161 | |
162 class AbstractMetaType | |
163 { | |
164 public: | |
165 enum TypeUsagePattern { | |
166 InvalidPattern, | |
167 PrimitivePattern, | |
168 FlagsPattern, | |
169 EnumPattern, | |
170 ValuePattern, | |
171 StringPattern, | |
172 CharPattern, | |
173 ObjectPattern, | |
174 QObjectPattern, | |
175 NativePointerPattern, | |
176 ContainerPattern, | |
177 VariantPattern, | |
178 JObjectWrapperPattern, | |
179 ArrayPattern, | |
180 ThreadPattern | |
181 }; | |
182 | |
183 AbstractMetaType() : | |
184 m_type_entry(0), | |
185 m_array_element_count(0), | |
186 m_array_element_type(0), | |
187 m_original_template_type(0), | |
188 m_pattern(InvalidPattern), | |
189 m_constant(false), | |
190 m_reference(false), | |
191 m_cpp_instantiation(true), | |
192 m_indirections(0), | |
193 m_reserved(0) | |
194 { | |
195 } | |
196 | |
197 QString package() const { return m_type_entry->javaPackage(); } | |
198 QString name() const { return m_type_entry->targetLangName(); } | |
199 QString fullName() const { return m_type_entry->qualifiedTargetLangName(); } | |
200 | |
201 void setTypeUsagePattern(TypeUsagePattern pattern) { m_pattern = pattern; } | |
202 TypeUsagePattern typeUsagePattern() const { return m_pattern; } | |
203 | |
204 // true when use pattern is container | |
205 bool hasInstantiations() const { return !m_instantiations.isEmpty(); } | |
206 void addInstantiation(AbstractMetaType *inst) { m_instantiations << inst; } | |
207 void setInstantiations(const QList<AbstractMetaType *> &insts) { m_instantiations = insts; } | |
208 QList<AbstractMetaType *> instantiations() const { return m_instantiations; } | |
209 void setInstantiationInCpp(bool incpp) { m_cpp_instantiation = incpp; } | |
210 bool hasInstantiationInCpp() const { return hasInstantiations() && m_cpp_instantiation; } | |
211 | |
212 QString minimalSignature() const; | |
213 | |
214 // true when the type is a QtJambiObject subclass | |
215 bool hasNativeId() const; | |
216 | |
217 // returns true if the typs is used as a non complex primitive, no & or *'s | |
218 bool isPrimitive() const { return m_pattern == PrimitivePattern; } | |
219 | |
220 // returns true if the type is used as an enum | |
221 bool isEnum() const { return m_pattern == EnumPattern; } | |
222 | |
223 // returns true if the type is used as a QObject * | |
224 bool isQObject() const { return m_pattern == QObjectPattern; } | |
225 | |
226 // returns true if the type is used as an object, e.g. Xxx * | |
227 bool isObject() const { return m_pattern == ObjectPattern; } | |
228 | |
229 // returns true if the type is used as an array, e.g. Xxx[42] | |
230 bool isArray() const { return m_pattern == ArrayPattern; } | |
231 | |
232 // returns true if the type is used as a value type (X or const X &) | |
233 bool isValue() const { return m_pattern == ValuePattern; } | |
234 | |
235 // returns true for more complex types... | |
236 bool isNativePointer() const { return m_pattern == NativePointerPattern; } | |
237 | |
238 // returns true if the type was originally a QString or const QString & or equivalent for QLatin1String | |
239 bool isTargetLangString() const { return m_pattern == StringPattern; } | |
240 | |
241 // returns true if the type was originally a QChar or const QChar & | |
242 bool isTargetLangChar() const { return m_pattern == CharPattern; } | |
243 | |
244 // return true if the type was originally a QVariant or const QVariant & | |
245 bool isVariant() const { return m_pattern == VariantPattern; } | |
246 | |
247 // return true if the type was originally a JObjectWrapper or const JObjectWrapper & | |
248 bool isJObjectWrapper() const { return m_pattern == JObjectWrapperPattern; } | |
249 | |
250 // returns true if the type was used as a container | |
251 bool isContainer() const { return m_pattern == ContainerPattern; } | |
252 | |
253 // returns true if the type was used as a flag | |
254 bool isFlags() const { return m_pattern == FlagsPattern; } | |
255 | |
256 // returns true if the type was used as a thread | |
257 bool isThread() const { return m_pattern == ThreadPattern; } | |
258 | |
259 bool isConstant() const { return m_constant; } | |
260 void setConstant(bool constant) { m_constant = constant; } | |
261 | |
262 bool isReference() const { return m_reference; } | |
263 void setReference(bool ref) { m_reference = ref; } | |
264 | |
265 // Returns true if the type is to be implemented using Java enums, e.g. not plain ints. | |
266 bool isTargetLangEnum() const { return isEnum() && !((EnumTypeEntry *) typeEntry())->forceInteger(); } | |
267 bool isIntegerEnum() const { return isEnum() && !isTargetLangEnum(); } | |
268 | |
269 // Returns true if the type is to be implemented using Java QFlags, e.g. not plain ints. | |
270 bool isTargetLangFlags() const { | |
271 return isFlags() && !((FlagsTypeEntry *) typeEntry())->forceInteger(); } | |
272 bool isIntegerFlags() const { return isFlags() && !isTargetLangFlags(); } | |
273 | |
274 int actualIndirections() const { return m_indirections + (isReference() ? 1 : 0); } | |
275 int indirections() const { return m_indirections; } | |
276 void setIndirections(int indirections) { m_indirections = indirections; } | |
277 | |
278 void setArrayElementCount(int n) { m_array_element_count = n; } | |
279 int arrayElementCount() const { return m_array_element_count; } | |
280 | |
281 AbstractMetaType *arrayElementType() const { return m_array_element_type; } | |
282 void setArrayElementType(AbstractMetaType *t) { m_array_element_type = t; } | |
283 | |
284 QString cppSignature() const; | |
285 | |
286 AbstractMetaType *copy() const; | |
287 | |
288 const TypeEntry *typeEntry() const { return m_type_entry; } | |
289 void setTypeEntry(const TypeEntry *type) { m_type_entry = type; } | |
290 | |
291 void setOriginalTypeDescription(const QString &otd) { m_original_type_description = otd; } | |
292 QString originalTypeDescription() const { return m_original_type_description; } | |
293 | |
294 void setOriginalTemplateType(const AbstractMetaType *type) { m_original_template_type = type; } | |
295 const AbstractMetaType *originalTemplateType() const { return m_original_template_type; } | |
296 | |
297 private: | |
298 const TypeEntry *m_type_entry; | |
299 QList <AbstractMetaType *> m_instantiations; | |
300 QString m_package; | |
301 QString m_original_type_description; | |
302 | |
303 int m_array_element_count; | |
304 AbstractMetaType *m_array_element_type; | |
305 const AbstractMetaType *m_original_template_type; | |
306 | |
307 TypeUsagePattern m_pattern; | |
308 uint m_constant : 1; | |
309 uint m_reference : 1; | |
310 uint m_cpp_instantiation : 1; | |
311 int m_indirections : 4; | |
312 uint m_reserved : 25; // unused | |
313 }; | |
314 | |
315 class AbstractMetaVariable | |
316 { | |
317 public: | |
318 AbstractMetaVariable() : m_type(0) { } | |
319 | |
320 AbstractMetaType *type() const { return m_type; } | |
321 void setType(AbstractMetaType *type) { m_type = type; } | |
322 | |
323 QString name() const { return m_name; } | |
324 void setName(const QString &name) { m_name = name; } | |
325 | |
326 private: | |
327 QString m_name; | |
328 AbstractMetaType *m_type; | |
329 }; | |
330 | |
331 | |
332 | |
333 class AbstractMetaArgument : public AbstractMetaVariable | |
334 { | |
335 public: | |
336 AbstractMetaArgument() : m_argument_index(0) { }; | |
337 | |
338 QString defaultValueExpression() const { return m_expression; } | |
339 void setDefaultValueExpression(const QString &expr) { m_expression = expr; } | |
340 | |
341 QString originalDefaultValueExpression() const { return m_original_expression; } | |
342 void setOriginalDefaultValueExpression(const QString &expr) { m_original_expression = expr; } | |
343 | |
344 QString toString() const { return type()->name() + " " + AbstractMetaVariable::name() + | |
345 (m_expression.isEmpty() ? "" : " = " + m_expression); } | |
346 | |
347 int argumentIndex() const { return m_argument_index; } | |
348 void setArgumentIndex(int argIndex) { m_argument_index = argIndex; } | |
349 | |
350 QString argumentName() const; | |
351 QString indexedName() const; | |
352 | |
353 AbstractMetaArgument *copy() const; | |
354 | |
355 private: | |
356 // Just to force people to call argumentName() And indexedName(); | |
357 QString name() const; | |
358 | |
359 QString m_expression; | |
360 QString m_original_expression; | |
361 int m_argument_index; | |
362 }; | |
363 | |
364 | |
365 class AbstractMetaField : public AbstractMetaVariable, public AbstractMetaAttributes | |
366 { | |
367 public: | |
368 AbstractMetaField(); | |
369 ~AbstractMetaField(); | |
370 | |
371 const AbstractMetaClass *enclosingClass() const { return m_class; } | |
372 void setEnclosingClass(const AbstractMetaClass *cls) { m_class = cls; } | |
373 | |
374 const AbstractMetaFunction *getter() const; | |
375 const AbstractMetaFunction *setter() const; | |
376 | |
377 FieldModificationList modifications() const; | |
378 | |
379 AbstractMetaField *copy() const; | |
380 | |
381 private: | |
382 mutable AbstractMetaFunction *m_getter; | |
383 mutable AbstractMetaFunction *m_setter; | |
384 const AbstractMetaClass *m_class; | |
385 }; | |
386 | |
387 | |
388 class AbstractMetaFunction : public AbstractMetaAttributes | |
389 { | |
390 public: | |
391 enum FunctionType { | |
392 ConstructorFunction, | |
393 DestructorFunction, | |
394 NormalFunction, | |
395 SignalFunction, | |
396 EmptyFunction, | |
397 SlotFunction, | |
398 GlobalScopeFunction | |
399 }; | |
400 | |
401 enum CompareResult { | |
402 EqualName = 0x00000001, | |
403 EqualArguments = 0x00000002, | |
404 EqualAttributes = 0x00000004, | |
405 EqualImplementor = 0x00000008, | |
406 EqualReturnType = 0x00000010, | |
407 EqualDefaultValueOverload = 0x00000020, | |
408 EqualModifiedName = 0x00000040, | |
409 | |
410 NameLessThan = 0x00001000, | |
411 | |
412 PrettySimilar = EqualName | EqualArguments, | |
413 Equal = 0x0000001f, | |
414 NotEqual = 0x00001000 | |
415 }; | |
416 | |
417 AbstractMetaFunction() | |
418 : m_function_type(NormalFunction), | |
419 m_type(0), | |
420 m_class(0), | |
421 m_implementing_class(0), | |
422 m_declaring_class(0), | |
423 m_interface_class(0), | |
424 m_property_spec(0), | |
425 m_constant(false), | |
426 m_invalid(false), | |
427 m_jumptable_id(-1), | |
428 // qtd | |
429 m_store_result(0) | |
430 { | |
431 } | |
432 | |
433 ~AbstractMetaFunction(); | |
434 | |
435 QString name() const { return m_name; } | |
436 void setName(const QString &name) { m_name = name; } | |
437 | |
438 QString originalName() const { return m_original_name.isEmpty() ? name() : m_original_name; } | |
439 void setOriginalName(const QString &name) { m_original_name = name; } | |
440 | |
441 QString modifiedName() const; | |
442 | |
288 | 443 QString minimalSignature(int reduce = 0) const; |
1 | 444 QStringList possibleIntrospectionCompatibleSignatures() const; |
445 | |
446 QString marshalledName(bool classIsOwner = true) const; | |
447 | |
448 // true if one or more of the arguments are of QtJambiObject subclasses | |
449 bool argumentsHaveNativeId() const | |
450 { | |
451 foreach (const AbstractMetaArgument *arg, m_arguments) { | |
452 if (arg->type()->hasNativeId()) | |
453 return true; | |
454 } | |
455 | |
456 return false; | |
457 } | |
458 | |
459 bool isModifiedRemoved(int types = TypeSystem::All) const; | |
460 | |
461 AbstractMetaType *type() const { return m_type; } | |
462 void setType(AbstractMetaType *type) { m_type = type; } | |
463 | |
464 // The class that has this function as a member. | |
465 const AbstractMetaClass *ownerClass() const { return m_class; } | |
466 void setOwnerClass(const AbstractMetaClass *cls) { m_class = cls; } | |
467 | |
468 // The first class in a hierarchy that declares the function | |
469 const AbstractMetaClass *declaringClass() const { return m_declaring_class; } | |
470 void setDeclaringClass(const AbstractMetaClass *cls) { m_declaring_class = cls; } | |
471 | |
472 // The class that actually implements this function | |
473 const AbstractMetaClass *implementingClass() const { return m_implementing_class; } | |
474 void setImplementingClass(const AbstractMetaClass *cls) { m_implementing_class = cls; } | |
475 | |
476 bool needsCallThrough() const; | |
477 | |
478 AbstractMetaArgumentList arguments() const { return m_arguments; } | |
479 void setArguments(const AbstractMetaArgumentList &arguments) { m_arguments = arguments; } | |
480 void addArgument(AbstractMetaArgument *argument) { m_arguments << argument; } | |
481 int actualMinimumArgumentCount() const; | |
482 | |
483 void setInvalid(bool on) { m_invalid = on; } | |
484 bool isInvalid() const { return m_invalid; } | |
485 bool isDeprecated() const; | |
486 bool isDestructor() const { return functionType() == DestructorFunction; } | |
487 bool isConstructor() const { return functionType() == ConstructorFunction; } | |
488 bool isNormal() const { return functionType() == NormalFunction || isSlot() || isInGlobalScope(); } | |
489 bool isInGlobalScope() const { return functionType() == GlobalScopeFunction; } | |
490 bool isSignal() const { return functionType() == SignalFunction; } | |
491 bool isSlot() const { return functionType() == SlotFunction; } | |
492 bool isEmptyFunction() const { return functionType() == EmptyFunction; } | |
493 FunctionType functionType() const { return m_function_type; } | |
494 void setFunctionType(FunctionType type) { m_function_type = type; } | |
495 | |
496 QStringList introspectionCompatibleSignatures(const QStringList &resolvedArguments = QStringList()) const; | |
497 QString signature() const; | |
498 QString targetLangSignature(bool minimal = false) const; | |
499 bool shouldReturnThisObject() const { return QLatin1String("this") == argumentReplaced(0); } | |
500 | |
501 bool isConstant() const { return m_constant; } | |
502 void setConstant(bool constant) { m_constant = constant; } | |
503 | |
504 QString toString() const { return m_name; } | |
505 | |
506 uint compareTo(const AbstractMetaFunction *other) const; | |
507 | |
508 bool operator <(const AbstractMetaFunction &a) const; | |
509 | |
510 AbstractMetaFunction *copy() const; | |
511 | |
512 QString replacedDefaultExpression(const AbstractMetaClass *cls, int idx) const; | |
513 bool removedDefaultExpression(const AbstractMetaClass *cls, int idx) const; | |
514 QString conversionRule(TypeSystem::Language language, int idx) const; | |
515 QList<ReferenceCount> referenceCounts(const AbstractMetaClass *cls, int idx = -2) const; | |
516 | |
517 bool nullPointersDisabled(const AbstractMetaClass *cls = 0, int argument_idx = 0) const; | |
518 QString nullPointerDefaultValue(const AbstractMetaClass *cls = 0, int argument_idx = 0) const; | |
519 | |
520 bool resetObjectAfterUse(int argument_idx) const; | |
521 | |
522 // Returns whether garbage collection is disabled for the argument in any context | |
523 bool disabledGarbageCollection(const AbstractMetaClass *cls, int key) const; | |
524 | |
525 // Returns the ownership rules for the given argument in the given context | |
526 TypeSystem::Ownership ownership(const AbstractMetaClass *cls, TypeSystem::Language language, int idx) const; | |
527 | |
528 bool isVirtualSlot() const; | |
529 | |
530 QString typeReplaced(int argument_index) const; | |
531 bool isRemovedFromAllLanguages(const AbstractMetaClass *) const; | |
532 bool isRemovedFrom(const AbstractMetaClass *, TypeSystem::Language language) const; | |
533 bool argumentRemoved(int) const; | |
534 | |
535 QString argumentReplaced(int key) const; | |
536 bool needsSuppressUncheckedWarning() const; | |
537 | |
538 bool hasModifications(const AbstractMetaClass *implementor) const; | |
539 FunctionModificationList modifications(const AbstractMetaClass *implementor) const; | |
540 | |
541 // If this function stems from an interface, this returns the | |
542 // interface that declares it. | |
543 const AbstractMetaClass *interfaceClass() const { return m_interface_class; } | |
544 void setInterfaceClass(const AbstractMetaClass *cl) { m_interface_class = cl; } | |
545 | |
546 void setPropertySpec(QPropertySpec *spec) { m_property_spec = spec; } | |
547 QPropertySpec *propertySpec() const { return m_property_spec; } | |
548 | |
549 int jumpTableId() const { return m_jumptable_id; } | |
550 void setJumpTableId(int id) { m_jumptable_id = id; } | |
551 | |
552 // qtd | |
553 bool storeResult() const; | |
554 void checkStoreResult(); | |
555 | |
556 private: | |
557 int m_store_result; | |
558 | |
559 private: | |
560 QString m_name; | |
561 QString m_original_name; | |
562 mutable QString m_cached_minimal_signature; | |
563 mutable QString m_cached_modified_name; | |
564 | |
565 FunctionType m_function_type; | |
566 AbstractMetaType *m_type; | |
567 const AbstractMetaClass *m_class; | |
568 const AbstractMetaClass *m_implementing_class; | |
569 const AbstractMetaClass *m_declaring_class; | |
570 const AbstractMetaClass *m_interface_class; | |
571 QPropertySpec *m_property_spec; | |
572 AbstractMetaArgumentList m_arguments; | |
573 uint m_constant : 1; | |
574 uint m_invalid : 1; | |
575 int m_jumptable_id; | |
576 }; | |
577 | |
578 | |
579 class AbstractMetaEnumValue | |
580 { | |
581 public: | |
582 AbstractMetaEnumValue() | |
583 : m_value_set(false), m_value(0) | |
584 { | |
585 } | |
586 | |
587 int value() const { return m_value; } | |
588 void setValue(int value) { m_value_set = true; m_value = value; } | |
589 | |
590 QString stringValue() const { return m_string_value; } | |
591 void setStringValue(const QString &v) { m_string_value = v; } | |
592 | |
593 QString name() const { return m_name; } | |
594 void setName(const QString &name) { m_name = name; } | |
595 | |
596 bool isValueSet() const { return m_value_set; } | |
597 | |
598 private: | |
599 QString m_name; | |
600 QString m_string_value; | |
601 | |
602 bool m_value_set; | |
603 int m_value; | |
604 }; | |
605 | |
606 | |
607 class AbstractMetaEnumValueList : public QList<AbstractMetaEnumValue *> | |
608 { | |
609 public: | |
610 AbstractMetaEnumValue *find(const QString &name) const; | |
611 }; | |
612 | |
613 class AbstractMetaEnum : public AbstractMetaAttributes | |
614 { | |
615 public: | |
616 AbstractMetaEnum() : m_type_entry(0), m_class(0), m_has_qenums_declaration(false) {} | |
617 | |
618 AbstractMetaEnumValueList values() const { return m_enum_values; } | |
619 void addEnumValue(AbstractMetaEnumValue *enumValue) { m_enum_values << enumValue; } | |
620 | |
621 QString name() const { return m_type_entry->targetLangName(); } | |
622 QString qualifier() const { return m_type_entry->javaQualifier(); } | |
623 QString package() const { return m_type_entry->javaPackage(); } | |
624 QString fullName() const { return package() + "." + qualifier() + "." + name(); } | |
625 | |
626 // Has the enum been declared inside a Q_ENUMS() macro in its enclosing class? | |
627 void setHasQEnumsDeclaration(bool on) { m_has_qenums_declaration = on; } | |
628 bool hasQEnumsDeclaration() const { return m_has_qenums_declaration; } | |
629 | |
630 EnumTypeEntry *typeEntry() const { return m_type_entry; } | |
631 void setTypeEntry(EnumTypeEntry *entry) { m_type_entry = entry; } | |
632 | |
633 AbstractMetaClass *enclosingClass() const { return m_class; } | |
634 void setEnclosingClass(AbstractMetaClass *c) { m_class = c; } | |
635 | |
636 private: | |
637 AbstractMetaEnumValueList m_enum_values; | |
638 EnumTypeEntry *m_type_entry; | |
639 AbstractMetaClass *m_class; | |
640 | |
641 uint m_has_qenums_declaration : 1; | |
642 uint m_reserved : 31; | |
643 }; | |
644 | |
645 typedef QList<AbstractMetaEnum *> AbstractMetaEnumList; | |
646 | |
647 class AbstractMetaClass : public AbstractMetaAttributes | |
648 { | |
649 public: | |
650 enum FunctionQueryOption { | |
651 Constructors = 0x000001, // Only constructors | |
652 //Destructors = 0x000002, // Only destructors. Not included in class. | |
653 VirtualFunctions = 0x000004, // Only virtual functions (virtual in both TargetLang and C++) | |
654 FinalInTargetLangFunctions = 0x000008, // Only functions that are non-virtual in TargetLang | |
655 FinalInCppFunctions = 0x000010, // Only functions that are non-virtual in C++ | |
656 ClassImplements = 0x000020, // Only functions implemented by the current class | |
657 Inconsistent = 0x000040, // Only inconsistent functions (inconsistent virtualness in TargetLang/C++) | |
658 StaticFunctions = 0x000080, // Only static functions | |
659 Signals = 0x000100, // Only signals | |
660 NormalFunctions = 0x000200, // Only functions that aren't signals | |
661 Visible = 0x000400, // Only public and protected functions | |
662 ForcedShellFunctions = 0x000800, // Only functions that are overridden to be implemented in the shell class | |
663 WasPublic = 0x001000, // Only functions that were originally public | |
664 WasProtected = 0x002000, // Only functions that were originally protected | |
665 NonStaticFunctions = 0x004000, // No static functions | |
666 Empty = 0x008000, // Empty overrides of abstract functions | |
667 Invisible = 0x010000, // Only private functions | |
668 VirtualInCppFunctions = 0x020000, // Only functions that are virtual in C++ | |
669 NonEmptyFunctions = 0x040000, // Only functions with JNI implementations | |
670 VirtualInTargetLangFunctions = 0x080000, // Only functions which are virtual in TargetLang | |
671 AbstractFunctions = 0x100000, // Only abstract functions | |
672 WasVisible = 0x200000, // Only functions that were public or protected in the original code | |
673 NotRemovedFromTargetLang = 0x400000, // Only functions that have not been removed from TargetLang | |
674 NotRemovedFromShell = 0x800000, // Only functions that have not been removed from the shell class | |
675 VirtualSlots = 0x1000000 // Only functions that are set as virtual slots in the type system | |
676 }; | |
677 | |
678 AbstractMetaClass() | |
679 : m_namespace(false), | |
680 m_qobject(false), | |
681 m_has_virtuals(false), | |
682 m_has_nonpublic(false), | |
683 m_has_virtual_slots(false), | |
684 m_has_nonprivateconstructor(false), | |
685 m_functions_fixed(false), | |
686 m_has_public_destructor(true), | |
687 m_force_shell_class(false), | |
688 m_has_hash_function(false), | |
689 m_has_equals_operator(false), | |
690 m_has_clone_operator(false), | |
691 m_is_type_alias(false), | |
692 m_enclosing_class(0), | |
693 m_base_class(0), | |
694 m_template_base_class(0), | |
695 m_extracted_interface(0), | |
696 m_primary_interface_implementor(0), | |
697 m_type_entry(0), | |
110 | 698 m_qDebug_stream_function(0), |
699 needsConversionFunc(false) | |
1 | 700 { |
701 } | |
702 | |
703 virtual ~AbstractMetaClass(); | |
704 | |
705 AbstractMetaClass *extractInterface(); | |
706 void fixFunctions(); | |
707 | |
708 AbstractMetaFunctionList functions() const { return m_functions; } | |
709 void setFunctions(const AbstractMetaFunctionList &functions); | |
710 void addFunction(AbstractMetaFunction *function); | |
711 bool hasFunction(const AbstractMetaFunction *f) const; | |
712 bool hasFunction(const QString &str) const; | |
713 bool hasSignal(const AbstractMetaFunction *f) const; | |
714 | |
715 bool hasConstructors() const; | |
293 | 716 AbstractMetaFunction *copyConstructor() const; |
1 | 717 |
718 void addDefaultConstructor(); | |
719 | |
720 bool hasNonPrivateConstructor() const { return m_has_nonprivateconstructor; } | |
721 void setHasNonPrivateConstructor(bool on) { m_has_nonprivateconstructor = on; } | |
722 bool hasPublicDestructor() const { return m_has_public_destructor; } | |
723 void setHasPublicDestructor(bool on) { m_has_public_destructor = on; } | |
724 | |
725 AbstractMetaFunctionList queryFunctionsByName(const QString &name) const; | |
726 AbstractMetaFunctionList queryFunctions(uint query) const; | |
727 inline AbstractMetaFunctionList allVirtualFunctions() const; | |
728 inline AbstractMetaFunctionList allFinalFunctions() const; | |
729 AbstractMetaFunctionList functionsInTargetLang() const; | |
730 AbstractMetaFunctionList functionsInShellClass() const; | |
731 inline AbstractMetaFunctionList cppInconsistentFunctions() const; | |
732 inline AbstractMetaFunctionList cppSignalFunctions() const; | |
733 AbstractMetaFunctionList publicOverrideFunctions() const; | |
734 AbstractMetaFunctionList virtualOverrideFunctions() const; | |
735 AbstractMetaFunctionList virtualFunctions() const; | |
736 AbstractMetaFunctionList nonVirtualShellFunctions() const; | |
737 | |
738 AbstractMetaFieldList fields() const { return m_fields; } | |
739 void setFields(const AbstractMetaFieldList &fields) { m_fields = fields; } | |
740 void addField(AbstractMetaField *field) { m_fields << field; } | |
741 | |
742 AbstractMetaEnumList enums() const { return m_enums; } | |
743 void setEnums(const AbstractMetaEnumList &enums) { m_enums = enums; } | |
744 void addEnum(AbstractMetaEnum *e) { m_enums << e; } | |
745 | |
746 AbstractMetaEnum *findEnum(const QString &enumName); | |
747 AbstractMetaEnum *findEnumForValue(const QString &enumName); | |
748 AbstractMetaEnumValue *findEnumValue(const QString &enumName, AbstractMetaEnum *meta_enum); | |
749 | |
750 AbstractMetaClassList interfaces() const { return m_interfaces; } | |
751 void addInterface(AbstractMetaClass *interface); | |
752 void setInterfaces(const AbstractMetaClassList &interface); | |
753 | |
754 QString fullName() const { return package() + "." + name(); } | |
755 QString name() const; | |
756 | |
757 QString baseClassName() const { return m_base_class ? m_base_class->name() : QString(); } | |
758 | |
759 AbstractMetaClass *baseClass() const { return m_base_class; } | |
760 void setBaseClass(AbstractMetaClass *base_class) { m_base_class = base_class; } | |
761 | |
762 const AbstractMetaClass *enclosingClass() const { return m_enclosing_class; } | |
763 void setEnclosingClass(AbstractMetaClass *cl) { m_enclosing_class = cl; } | |
764 | |
765 QString package() const { return m_type_entry->javaPackage(); } | |
766 bool isInterface() const { return m_type_entry->isInterface(); } | |
767 bool isNamespace() const { return m_type_entry->isNamespace(); } | |
768 bool isQObject() const { return m_type_entry->isQObject(); } | |
769 bool isQtNamespace() const { return isNamespace() && name() == "Qt"; } | |
770 QString qualifiedCppName() const { return m_type_entry->qualifiedCppName(); } | |
771 | |
772 bool hasInconsistentFunctions() const; | |
773 bool hasSignals() const; | |
774 bool inheritsFrom(const AbstractMetaClass *other) const; | |
775 | |
776 void setForceShellClass(bool on) { m_force_shell_class = on; } | |
777 bool generateShellClass() const; | |
778 | |
779 bool hasVirtualSlots() const { return m_has_virtual_slots; } | |
780 bool hasVirtualFunctions() const { return !isFinal() && m_has_virtuals; } | |
781 bool hasProtectedFunctions() const; | |
782 | |
783 QList<TypeEntry *> templateArguments() const { return m_template_args; } | |
784 void setTemplateArguments(const QList<TypeEntry *> &args) { m_template_args = args; } | |
785 | |
786 bool hasFieldAccessors() const; | |
787 | |
788 // only valid during metajavabuilder's run | |
789 QStringList baseClassNames() const { return m_base_class_names; } | |
790 void setBaseClassNames(const QStringList &names) { m_base_class_names = names; } | |
791 | |
792 AbstractMetaClass *primaryInterfaceImplementor() const { return m_primary_interface_implementor; } | |
793 void setPrimaryInterfaceImplementor(AbstractMetaClass *cl) { m_primary_interface_implementor = cl; } | |
794 | |
795 const ComplexTypeEntry *typeEntry() const { return m_type_entry; } | |
796 ComplexTypeEntry *typeEntry() { return m_type_entry; } | |
797 void setTypeEntry(ComplexTypeEntry *type) { m_type_entry = type; } | |
798 | |
799 void setHasHashFunction(bool on) { m_has_hash_function = on; } | |
800 bool hasHashFunction() const { return m_has_hash_function; } | |
801 | |
802 void setToStringCapability(FunctionModelItem fun) { m_qDebug_stream_function= fun; } | |
803 FunctionModelItem hasToStringCapability() const { return m_qDebug_stream_function; } | |
804 | |
805 virtual bool hasDefaultToStringFunction() const; | |
806 | |
807 void setHasEqualsOperator(bool on) { m_has_equals_operator = on; } | |
808 bool hasEqualsOperator() const { return m_has_equals_operator; } | |
809 | |
810 void setHasCloneOperator(bool on) { m_has_clone_operator = on; } | |
811 bool hasCloneOperator() const { return m_has_clone_operator; } | |
812 | |
813 void addPropertySpec(QPropertySpec *spec) { m_property_specs << spec; } | |
814 QList<QPropertySpec *> propertySpecs() const { return m_property_specs; } | |
815 | |
816 QPropertySpec *propertySpecForRead(const QString &name) const; | |
817 QPropertySpec *propertySpecForWrite(const QString &name) const; | |
818 QPropertySpec *propertySpecForReset(const QString &name) const; | |
819 | |
820 QList<ReferenceCount> referenceCounts() const; | |
821 | |
822 void setEqualsFunctions(const AbstractMetaFunctionList &lst) { m_equals_functions = lst; } | |
823 AbstractMetaFunctionList equalsFunctions() const { return m_equals_functions; } | |
824 | |
825 void setNotEqualsFunctions(const AbstractMetaFunctionList &lst) { m_nequals_functions = lst; } | |
826 AbstractMetaFunctionList notEqualsFunctions() const { return m_nequals_functions; } | |
827 | |
828 void setLessThanFunctions(const AbstractMetaFunctionList &lst) { m_less_than_functions = lst; } | |
829 AbstractMetaFunctionList lessThanFunctions() const { return m_less_than_functions; } | |
830 | |
831 void setGreaterThanFunctions(const AbstractMetaFunctionList &lst) { m_greater_than_functions = lst; } | |
832 AbstractMetaFunctionList greaterThanFunctions() const { return m_greater_than_functions; } | |
833 | |
834 void setLessThanEqFunctions(const AbstractMetaFunctionList &lst) { m_less_than_eq_functions = lst; } | |
835 AbstractMetaFunctionList lessThanEqFunctions() const { return m_less_than_eq_functions; } | |
836 | |
837 void setGreaterThanEqFunctions(const AbstractMetaFunctionList &lst) { m_greater_than_eq_functions = lst; } | |
838 AbstractMetaFunctionList greaterThanEqFunctions() const { return m_greater_than_eq_functions; } | |
839 | |
840 void sortFunctions(); | |
841 | |
842 const AbstractMetaClass *templateBaseClass() const { return m_template_base_class; } | |
843 void setTemplateBaseClass(const AbstractMetaClass *cls) { m_template_base_class = cls; } | |
844 | |
845 void setTypeAlias(bool typeAlias) { m_is_type_alias = typeAlias; } | |
846 bool isTypeAlias() const { return m_is_type_alias; } | |
847 | |
42 | 848 const QStringList &depends() { return m_type_entry->depends(); } |
110 | 849 |
850 bool needsConversionFunc; | |
1 | 851 private: |
852 uint m_namespace : 1; | |
853 uint m_qobject : 1; | |
854 uint m_has_virtuals : 1; | |
855 uint m_has_nonpublic : 1; | |
856 uint m_has_virtual_slots : 1; | |
857 uint m_has_nonprivateconstructor : 1; | |
858 uint m_functions_fixed : 1; | |
859 uint m_has_public_destructor : 1; | |
860 uint m_force_shell_class : 1; | |
861 uint m_has_hash_function : 1; | |
862 uint m_has_equals_operator : 1; | |
863 uint m_has_clone_operator :1; | |
864 uint m_is_type_alias : 1; | |
865 uint m_reserved : 19; | |
866 | |
867 const AbstractMetaClass *m_enclosing_class; | |
868 AbstractMetaClass *m_base_class; | |
869 const AbstractMetaClass *m_template_base_class; | |
870 AbstractMetaFunctionList m_functions; | |
871 AbstractMetaFieldList m_fields; | |
872 AbstractMetaEnumList m_enums; | |
873 AbstractMetaClassList m_interfaces; | |
874 AbstractMetaClass *m_extracted_interface; | |
875 AbstractMetaClass *m_primary_interface_implementor; | |
876 QList<QPropertySpec *> m_property_specs; | |
877 AbstractMetaFunctionList m_equals_functions; | |
878 AbstractMetaFunctionList m_nequals_functions; | |
879 | |
880 AbstractMetaFunctionList m_less_than_functions; | |
881 AbstractMetaFunctionList m_greater_than_functions; | |
882 AbstractMetaFunctionList m_less_than_eq_functions; | |
883 AbstractMetaFunctionList m_greater_than_eq_functions; | |
884 | |
885 QStringList m_base_class_names; | |
886 QList<TypeEntry *> m_template_args; | |
887 ComplexTypeEntry *m_type_entry; | |
888 FunctionModelItem m_qDebug_stream_function; | |
889 | |
890 // qtd2 hack | |
891 friend class DGenerator; | |
892 }; | |
893 | |
894 class QPropertySpec { | |
895 public: | |
896 QPropertySpec(const TypeEntry *type) | |
897 : m_type(type), | |
898 m_index(-1) | |
899 { | |
900 } | |
901 | |
902 const TypeEntry *type() const { return m_type; } | |
903 | |
904 QString name() const { return m_name; } | |
905 void setName(const QString &name) { m_name = name; } | |
906 | |
907 QString read() const { return m_read; } | |
908 void setRead(const QString &read) { m_read = read; } | |
909 | |
910 QString write() const { return m_write; } | |
911 void setWrite(const QString &write) { m_write = write; } | |
912 | |
913 QString designable() const { return m_designable; } | |
914 void setDesignable(const QString &designable) { m_designable = designable; } | |
915 | |
916 QString reset() const { return m_reset; } | |
917 void setReset(const QString &reset) { m_reset = reset; } | |
918 | |
919 int index() const { return m_index; } | |
920 void setIndex(int index) { m_index = index; } | |
921 | |
922 private: | |
923 QString m_name; | |
924 QString m_read; | |
925 QString m_write; | |
926 QString m_designable; | |
927 QString m_reset; | |
928 const TypeEntry *m_type; | |
929 int m_index; | |
930 }; | |
931 | |
932 // qtd | |
933 class ArgumentReplace | |
934 { | |
935 private: | |
936 QHash<QString, QString> data; | |
937 static ArgumentReplace *m_instance; | |
938 ArgumentReplace(); | |
939 | |
940 public: | |
941 static void init(); | |
942 static QString translate(QString arg); | |
943 }; | |
944 | |
945 inline AbstractMetaFunctionList AbstractMetaClass::allVirtualFunctions() const | |
946 { | |
947 return queryFunctions(VirtualFunctions | |
948 | NotRemovedFromTargetLang); | |
949 } | |
950 | |
951 inline AbstractMetaFunctionList AbstractMetaClass::allFinalFunctions() const | |
952 { | |
953 return queryFunctions(FinalInTargetLangFunctions | |
954 | FinalInCppFunctions | |
955 | NotRemovedFromTargetLang); | |
956 } | |
957 | |
958 inline AbstractMetaFunctionList AbstractMetaClass::cppInconsistentFunctions() const | |
959 { | |
960 return queryFunctions(Inconsistent | |
961 | NormalFunctions | |
962 | Visible | |
963 | NotRemovedFromTargetLang); | |
964 } | |
965 | |
966 inline AbstractMetaFunctionList AbstractMetaClass::cppSignalFunctions() const | |
967 { | |
968 return queryFunctions(Signals | |
969 | Visible | |
970 | NotRemovedFromTargetLang); | |
971 } | |
972 | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
293
diff
changeset
|
973 inline bool isNativeContainer(AbstractMetaType *argumentType) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
293
diff
changeset
|
974 { |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
293
diff
changeset
|
975 if (argumentType && argumentType->isContainer()) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
293
diff
changeset
|
976 if (((const ContainerTypeEntry *)argumentType->typeEntry())->isQList()) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
293
diff
changeset
|
977 return true; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
293
diff
changeset
|
978 return false; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
293
diff
changeset
|
979 } |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
293
diff
changeset
|
980 |
1 | 981 #endif // ABSTRACTMETALANG_H |