add bindings for QGraphicsSceneDragDropEvent
[qtscriptgenerator.git] / generator / abstractmetalang.h
bloba69b4068eb1e7112f12283970ae25ce6905b5891
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
6 **
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 ****************************************************************************/
24 #ifndef ABSTRACTMETALANG_H
25 #define ABSTRACTMETALANG_H
27 #include "codemodel.h"
29 #include "typesystem.h"
31 #include <QSet>
32 #include <QStringList>
33 #include <QTextStream>
36 class AbstractMeta;
37 class AbstractMetaClass;
38 class AbstractMetaField;
39 class AbstractMetaFunction;
40 class AbstractMetaType;
41 class AbstractMetaVariable;
42 class AbstractMetaArgument;
43 class AbstractMetaEnumValue;
44 class AbstractMetaEnum;
45 class QPropertySpec;
47 typedef QList<AbstractMetaField *> AbstractMetaFieldList;
48 typedef QList<AbstractMetaArgument *> AbstractMetaArgumentList;
49 typedef QList<AbstractMetaFunction *> AbstractMetaFunctionList;
50 class AbstractMetaClassList : public QList<AbstractMetaClass *>
52 public:
53 AbstractMetaClass *findClass(const QString &name) const;
54 AbstractMetaEnumValue *findEnumValue(const QString &string) const;
55 AbstractMetaEnum *findEnum(const EnumTypeEntry *entry) const;
61 class AbstractMetaAttributes
63 public:
64 AbstractMetaAttributes() : m_attributes(0) { };
66 enum Attribute {
67 None = 0x00000000,
69 Private = 0x00000001,
70 Protected = 0x00000002,
71 Public = 0x00000004,
72 Friendly = 0x00000008,
73 Visibility = 0x0000000f,
75 Native = 0x00000010,
76 Abstract = 0x00000020,
77 Static = 0x00000040,
79 FinalInTargetLang = 0x00000080,
80 FinalInCpp = 0x00000100,
81 ForceShellImplementation = 0x00000200,
83 GetterFunction = 0x00000400,
84 SetterFunction = 0x00000800,
86 FinalOverload = 0x00001000,
87 InterfaceFunction = 0x00002000,
89 PropertyReader = 0x00004000,
90 PropertyWriter = 0x00008000,
91 PropertyResetter = 0x00010000,
93 Fake = 0x00020000,
95 Invokable = 0x00040000,
97 Final = FinalInTargetLang | FinalInCpp
100 uint attributes() const { return m_attributes; }
101 void setAttributes(uint attributes) { m_attributes = attributes; }
103 uint originalAttributes() const { return m_originalAttributes; }
104 void setOriginalAttributes(uint attributes) { m_originalAttributes = attributes; }
106 uint visibility() const { return m_attributes & Visibility; }
107 void setVisibility(uint visi) { m_attributes = (m_attributes & ~Visibility) | visi; }
109 void operator+=(Attribute attribute) { m_attributes |= attribute; }
110 void operator-=(Attribute attribute) { m_attributes &= ~attribute; }
112 bool isNative() const { return m_attributes & Native; }
113 bool isFinal() const { return (m_attributes & Final) == Final; }
114 bool isFinalInTargetLang() const { return m_attributes & FinalInTargetLang; }
115 bool isFinalInCpp() const { return m_attributes & FinalInCpp; }
116 bool isAbstract() const { return m_attributes & Abstract; }
117 bool isStatic() const { return m_attributes & Static; }
118 bool isForcedShellImplementation() const { return m_attributes & ForceShellImplementation; }
119 bool isInterfaceFunction() const { return m_attributes & InterfaceFunction; }
120 bool isFinalOverload() const { return m_attributes & FinalOverload; }
121 bool isInvokable() const { return m_attributes & Invokable; }
123 bool isPropertyReader() const { return m_attributes & PropertyReader; }
124 bool isPropertyWriter() const { return m_attributes & PropertyWriter; }
125 bool isPropertyResetter() const { return m_attributes & PropertyResetter; }
127 bool isPrivate() const { return m_attributes & Private; }
128 bool isProtected() const { return m_attributes & Protected; }
129 bool isPublic() const { return m_attributes & Public; }
130 bool isFriendly() const { return m_attributes & Friendly; }
132 bool wasPrivate() const { return m_originalAttributes & Private; }
133 bool wasProtected() const { return m_originalAttributes & Protected; }
134 bool wasPublic() const { return m_originalAttributes & Public; }
135 bool wasFriendly() const { return m_originalAttributes & Friendly; }
137 private:
138 uint m_attributes;
139 uint m_originalAttributes;
143 class AbstractMetaType
145 public:
146 enum TypeUsagePattern {
147 InvalidPattern,
148 PrimitivePattern,
149 FlagsPattern,
150 EnumPattern,
151 ValuePattern,
152 StringPattern,
153 CharPattern,
154 ObjectPattern,
155 QObjectPattern,
156 NativePointerPattern,
157 ContainerPattern,
158 VariantPattern,
159 JObjectWrapperPattern,
160 ArrayPattern,
161 ThreadPattern
164 AbstractMetaType() :
165 m_type_entry(0),
166 m_array_element_count(0),
167 m_array_element_type(0),
168 m_original_template_type(0),
169 m_pattern(InvalidPattern),
170 m_constant(false),
171 m_reference(false),
172 m_cpp_instantiation(true),
173 m_indirections(0),
174 m_reserved(0)
178 QString package() const { return m_type_entry->javaPackage(); }
179 QString name() const { return m_type_entry->targetLangName(); }
180 QString fullName() const { return m_type_entry->qualifiedTargetLangName(); }
182 void setTypeUsagePattern(TypeUsagePattern pattern) { m_pattern = pattern; }
183 TypeUsagePattern typeUsagePattern() const { return m_pattern; }
185 // true when use pattern is container
186 bool hasInstantiations() const { return !m_instantiations.isEmpty(); }
187 void addInstantiation(AbstractMetaType *inst) { m_instantiations << inst; }
188 void setInstantiations(const QList<AbstractMetaType *> &insts) { m_instantiations = insts; }
189 QList<AbstractMetaType *> instantiations() const { return m_instantiations; }
190 void setInstantiationInCpp(bool incpp) { m_cpp_instantiation = incpp; }
191 bool hasInstantiationInCpp() const { return hasInstantiations() && m_cpp_instantiation; }
193 QString minimalSignature() const;
195 // true when the type is a QtJambiObject subclass
196 bool hasNativeId() const;
198 // returns true if the typs is used as a non complex primitive, no & or *'s
199 bool isPrimitive() const { return m_pattern == PrimitivePattern; }
201 // returns true if the type is used as an enum
202 bool isEnum() const { return m_pattern == EnumPattern; }
204 // returns true if the type is used as a QObject *
205 bool isQObject() const { return m_pattern == QObjectPattern; }
207 // returns true if the type is used as an object, e.g. Xxx *
208 bool isObject() const { return m_pattern == ObjectPattern; }
210 // returns true if the type is used as an array, e.g. Xxx[42]
211 bool isArray() const { return m_pattern == ArrayPattern; }
213 // returns true if the type is used as a value type (X or const X &)
214 bool isValue() const { return m_pattern == ValuePattern; }
216 // returns true for more complex types...
217 bool isNativePointer() const { return m_pattern == NativePointerPattern; }
219 // returns true if the type was originally a QString or const QString & or equivalent for QLatin1String
220 bool isTargetLangString() const { return m_pattern == StringPattern; }
222 // returns true if the type was originally a QChar or const QChar &
223 bool isTargetLangChar() const { return m_pattern == CharPattern; }
225 // return true if the type was originally a QVariant or const QVariant &
226 bool isVariant() const { return m_pattern == VariantPattern; }
228 // return true if the type was originally a JObjectWrapper or const JObjectWrapper &
229 bool isJObjectWrapper() const { return m_pattern == JObjectWrapperPattern; }
231 // returns true if the type was used as a container
232 bool isContainer() const { return m_pattern == ContainerPattern; }
234 // returns true if the type was used as a flag
235 bool isFlags() const { return m_pattern == FlagsPattern; }
237 // returns true if the type was used as a thread
238 bool isThread() const { return m_pattern == ThreadPattern; }
240 bool isConstant() const { return m_constant; }
241 void setConstant(bool constant) { m_constant = constant; }
243 bool isReference() const { return m_reference; }
244 void setReference(bool ref) { m_reference = ref; }
246 // Returns true if the type is to be implemented using Java enums, e.g. not plain ints.
247 bool isTargetLangEnum() const { return isEnum() && !((EnumTypeEntry *) typeEntry())->forceInteger(); }
248 bool isIntegerEnum() const { return isEnum() && !isTargetLangEnum(); }
250 // Returns true if the type is to be implemented using Java QFlags, e.g. not plain ints.
251 bool isTargetLangFlags() const {
252 return isFlags() && !((FlagsTypeEntry *) typeEntry())->forceInteger(); }
253 bool isIntegerFlags() const { return isFlags() && !isTargetLangFlags(); }
255 int actualIndirections() const { return m_indirections + (isReference() ? 1 : 0); }
256 int indirections() const { return m_indirections; }
257 void setIndirections(int indirections) { m_indirections = indirections; }
259 void setArrayElementCount(int n) { m_array_element_count = n; }
260 int arrayElementCount() const { return m_array_element_count; }
262 AbstractMetaType *arrayElementType() const { return m_array_element_type; }
263 void setArrayElementType(AbstractMetaType *t) { m_array_element_type = t; }
265 QString cppSignature() const;
267 AbstractMetaType *copy() const;
269 const TypeEntry *typeEntry() const { return m_type_entry; }
270 void setTypeEntry(const TypeEntry *type) { m_type_entry = type; }
272 void setOriginalTypeDescription(const QString &otd) { m_original_type_description = otd; }
273 QString originalTypeDescription() const { return m_original_type_description; }
275 void setOriginalTemplateType(const AbstractMetaType *type) { m_original_template_type = type; }
276 const AbstractMetaType *originalTemplateType() const { return m_original_template_type; }
278 private:
279 const TypeEntry *m_type_entry;
280 QList <AbstractMetaType *> m_instantiations;
281 QString m_package;
282 QString m_original_type_description;
284 int m_array_element_count;
285 AbstractMetaType *m_array_element_type;
286 const AbstractMetaType *m_original_template_type;
288 TypeUsagePattern m_pattern;
289 uint m_constant : 1;
290 uint m_reference : 1;
291 uint m_cpp_instantiation : 1;
292 int m_indirections : 4;
293 uint m_reserved : 25; // unused
296 class AbstractMetaVariable
298 public:
299 AbstractMetaVariable() : m_type(0) { }
301 AbstractMetaType *type() const { return m_type; }
302 void setType(AbstractMetaType *type) { m_type = type; }
304 QString name() const { return m_name; }
305 void setName(const QString &name) { m_name = name; }
307 private:
308 QString m_name;
309 AbstractMetaType *m_type;
314 class AbstractMetaArgument : public AbstractMetaVariable
316 public:
317 AbstractMetaArgument() : m_argument_index(0) { };
319 QString defaultValueExpression() const { return m_expression; }
320 void setDefaultValueExpression(const QString &expr) { m_expression = expr; }
322 QString originalDefaultValueExpression() const { return m_original_expression; }
323 void setOriginalDefaultValueExpression(const QString &expr) { m_original_expression = expr; }
325 QString toString() const { return type()->name() + " " + AbstractMetaVariable::name() +
326 (m_expression.isEmpty() ? "" : " = " + m_expression); }
328 int argumentIndex() const { return m_argument_index; }
329 void setArgumentIndex(int argIndex) { m_argument_index = argIndex; }
331 QString argumentName() const;
332 QString indexedName() const;
334 AbstractMetaArgument *copy() const;
336 private:
337 // Just to force people to call argumentName() And indexedName();
338 QString name() const;
340 QString m_expression;
341 QString m_original_expression;
342 int m_argument_index;
346 class AbstractMetaField : public AbstractMetaVariable, public AbstractMetaAttributes
348 public:
349 AbstractMetaField();
350 ~AbstractMetaField();
352 const AbstractMetaClass *enclosingClass() const { return m_class; }
353 void setEnclosingClass(const AbstractMetaClass *cls) { m_class = cls; }
355 const AbstractMetaFunction *getter() const;
356 const AbstractMetaFunction *setter() const;
358 FieldModificationList modifications() const;
360 AbstractMetaField *copy() const;
362 private:
363 mutable AbstractMetaFunction *m_getter;
364 mutable AbstractMetaFunction *m_setter;
365 const AbstractMetaClass *m_class;
369 class AbstractMetaFunction : public AbstractMetaAttributes
371 public:
372 enum FunctionType {
373 ConstructorFunction,
374 DestructorFunction,
375 NormalFunction,
376 SignalFunction,
377 EmptyFunction,
378 SlotFunction,
379 GlobalScopeFunction
382 enum CompareResult {
383 EqualName = 0x00000001,
384 EqualArguments = 0x00000002,
385 EqualAttributes = 0x00000004,
386 EqualImplementor = 0x00000008,
387 EqualReturnType = 0x00000010,
388 EqualDefaultValueOverload = 0x00000020,
389 EqualModifiedName = 0x00000040,
391 NameLessThan = 0x00001000,
393 PrettySimilar = EqualName | EqualArguments,
394 Equal = 0x0000001f,
395 NotEqual = 0x00001000
398 AbstractMetaFunction()
399 : m_function_type(NormalFunction),
400 m_type(0),
401 m_class(0),
402 m_implementing_class(0),
403 m_declaring_class(0),
404 m_interface_class(0),
405 m_property_spec(0),
406 m_constant(false),
407 m_invalid(false)
411 ~AbstractMetaFunction();
413 QString name() const { return m_name; }
414 void setName(const QString &name) { m_name = name; }
416 QString originalName() const { return m_original_name.isEmpty() ? name() : m_original_name; }
417 void setOriginalName(const QString &name) { m_original_name = name; }
419 QString modifiedName() const;
421 QString minimalSignature() const;
422 QStringList possibleIntrospectionCompatibleSignatures() const;
424 QString marshalledName() const;
426 // true if one or more of the arguments are of QtJambiObject subclasses
427 bool argumentsHaveNativeId() const
429 foreach (const AbstractMetaArgument *arg, m_arguments) {
430 if (arg->type()->hasNativeId())
431 return true;
434 return false;
437 bool isModifiedRemoved(int types = TypeSystem::All) const;
439 AbstractMetaType *type() const { return m_type; }
440 void setType(AbstractMetaType *type) { m_type = type; }
442 // The class that has this function as a member.
443 const AbstractMetaClass *ownerClass() const { return m_class; }
444 void setOwnerClass(const AbstractMetaClass *cls) { m_class = cls; }
446 // The first class in a hierarchy that declares the function
447 const AbstractMetaClass *declaringClass() const { return m_declaring_class; }
448 void setDeclaringClass(const AbstractMetaClass *cls) { m_declaring_class = cls; }
450 // The class that actually implements this function
451 const AbstractMetaClass *implementingClass() const { return m_implementing_class; }
452 void setImplementingClass(const AbstractMetaClass *cls) { m_implementing_class = cls; }
454 bool needsCallThrough() const;
456 AbstractMetaArgumentList arguments() const { return m_arguments; }
457 void setArguments(const AbstractMetaArgumentList &arguments) { m_arguments = arguments; }
458 void addArgument(AbstractMetaArgument *argument) { m_arguments << argument; }
459 int actualMinimumArgumentCount() const;
461 void setInvalid(bool on) { m_invalid = on; }
462 bool isInvalid() const { return m_invalid; }
463 bool isDeprecated() const;
464 bool isDestructor() const { return functionType() == DestructorFunction; }
465 bool isConstructor() const { return functionType() == ConstructorFunction; }
466 bool isNormal() const { return functionType() == NormalFunction || isSlot() || isInGlobalScope(); }
467 bool isInGlobalScope() const { return functionType() == GlobalScopeFunction; }
468 bool isSignal() const { return functionType() == SignalFunction; }
469 bool isSlot() const { return functionType() == SlotFunction; }
470 bool isEmptyFunction() const { return functionType() == EmptyFunction; }
471 FunctionType functionType() const { return m_function_type; }
472 void setFunctionType(FunctionType type) { m_function_type = type; }
474 QStringList introspectionCompatibleSignatures(const QStringList &resolvedArguments = QStringList()) const;
475 QString signature() const;
476 QString targetLangSignature(bool minimal = false) const;
477 bool shouldReturnThisObject() const { return QLatin1String("this") == argumentReplaced(0); }
478 bool shouldIgnoreReturnValue() const { return QLatin1String("void") == argumentReplaced(0); }
480 bool isConstant() const { return m_constant; }
481 void setConstant(bool constant) { m_constant = constant; }
483 QString toString() const { return m_name; }
485 uint compareTo(const AbstractMetaFunction *other) const;
487 bool operator <(const AbstractMetaFunction &a) const;
489 AbstractMetaFunction *copy() const;
491 QString replacedDefaultExpression(const AbstractMetaClass *cls, int idx) const;
492 bool removedDefaultExpression(const AbstractMetaClass *cls, int idx) const;
493 QString conversionRule(TypeSystem::Language language, int idx) const;
494 QList<ReferenceCount> referenceCounts(const AbstractMetaClass *cls, int idx = -2) const;
496 bool nullPointersDisabled(const AbstractMetaClass *cls = 0, int argument_idx = 0) const;
497 QString nullPointerDefaultValue(const AbstractMetaClass *cls = 0, int argument_idx = 0) const;
499 bool resetObjectAfterUse(int argument_idx) const;
501 // Returns whether garbage collection is disabled for the argument in any context
502 bool disabledGarbageCollection(const AbstractMetaClass *cls, int key) const;
504 // Returns the ownership rules for the given argument in the given context
505 TypeSystem::Ownership ownership(const AbstractMetaClass *cls, TypeSystem::Language language, int idx) const;
507 bool isVirtualSlot() const;
509 QString typeReplaced(int argument_index) const;
510 bool isRemovedFromAllLanguages(const AbstractMetaClass *) const;
511 bool isRemovedFrom(const AbstractMetaClass *, TypeSystem::Language language) const;
512 bool argumentRemoved(int) const;
514 QString argumentReplaced(int key) const;
515 bool needsSuppressUncheckedWarning() const;
517 bool hasModifications(const AbstractMetaClass *implementor) const;
518 FunctionModificationList modifications(const AbstractMetaClass *implementor) const;
520 // If this function stems from an interface, this returns the
521 // interface that declares it.
522 const AbstractMetaClass *interfaceClass() const { return m_interface_class; }
523 void setInterfaceClass(const AbstractMetaClass *cl) { m_interface_class = cl; }
525 void setPropertySpec(QPropertySpec *spec) { m_property_spec = spec; }
526 QPropertySpec *propertySpec() const { return m_property_spec; }
528 private:
529 QString m_name;
530 QString m_original_name;
531 mutable QString m_cached_minimal_signature;
532 mutable QString m_cached_modified_name;
534 FunctionType m_function_type;
535 AbstractMetaType *m_type;
536 const AbstractMetaClass *m_class;
537 const AbstractMetaClass *m_implementing_class;
538 const AbstractMetaClass *m_declaring_class;
539 const AbstractMetaClass *m_interface_class;
540 QPropertySpec *m_property_spec;
541 AbstractMetaArgumentList m_arguments;
542 uint m_constant : 1;
543 uint m_invalid : 1;
547 class AbstractMetaEnumValue
549 public:
550 AbstractMetaEnumValue()
551 : m_value_set(false), m_value(0)
555 int value() const { return m_value; }
556 void setValue(int value) { m_value_set = true; m_value = value; }
558 QString stringValue() const { return m_string_value; }
559 void setStringValue(const QString &v) { m_string_value = v; }
561 QString name() const { return m_name; }
562 void setName(const QString &name) { m_name = name; }
564 bool isValueSet() const { return m_value_set; }
566 private:
567 QString m_name;
568 QString m_string_value;
570 bool m_value_set;
571 int m_value;
575 class AbstractMetaEnumValueList : public QList<AbstractMetaEnumValue *>
577 public:
578 AbstractMetaEnumValue *find(const QString &name) const;
581 class AbstractMetaEnum : public AbstractMetaAttributes
583 public:
584 AbstractMetaEnum() : m_type_entry(0), m_class(0), m_has_qenums_declaration(false) {}
586 AbstractMetaEnumValueList values() const { return m_enum_values; }
587 void addEnumValue(AbstractMetaEnumValue *enumValue) { m_enum_values << enumValue; }
589 QString name() const { return m_type_entry->targetLangName(); }
590 QString qualifier() const { return m_type_entry->javaQualifier(); }
591 QString package() const { return m_type_entry->javaPackage(); }
592 QString fullName() const { return package() + "." + qualifier() + "." + name(); }
594 // Has the enum been declared inside a Q_ENUMS() macro in its enclosing class?
595 void setHasQEnumsDeclaration(bool on) { m_has_qenums_declaration = on; }
596 bool hasQEnumsDeclaration() const { return m_has_qenums_declaration; }
598 EnumTypeEntry *typeEntry() const { return m_type_entry; }
599 void setTypeEntry(EnumTypeEntry *entry) { m_type_entry = entry; }
601 AbstractMetaClass *enclosingClass() const { return m_class; }
602 void setEnclosingClass(AbstractMetaClass *c) { m_class = c; }
604 private:
605 AbstractMetaEnumValueList m_enum_values;
606 EnumTypeEntry *m_type_entry;
607 AbstractMetaClass *m_class;
609 uint m_has_qenums_declaration : 1;
610 uint m_reserved : 31;
613 typedef QList<AbstractMetaEnum *> AbstractMetaEnumList;
615 class AbstractMetaClass : public AbstractMetaAttributes
617 public:
618 enum FunctionQueryOption {
619 Constructors = 0x000001, // Only constructors
620 //Destructors = 0x000002, // Only destructors. Not included in class.
621 VirtualFunctions = 0x000004, // Only virtual functions (virtual in both TargetLang and C++)
622 FinalInTargetLangFunctions = 0x000008, // Only functions that are non-virtual in TargetLang
623 FinalInCppFunctions = 0x000010, // Only functions that are non-virtual in C++
624 ClassImplements = 0x000020, // Only functions implemented by the current class
625 Inconsistent = 0x000040, // Only inconsistent functions (inconsistent virtualness in TargetLang/C++)
626 StaticFunctions = 0x000080, // Only static functions
627 Signals = 0x000100, // Only signals
628 NormalFunctions = 0x000200, // Only functions that aren't signals
629 Visible = 0x000400, // Only public and protected functions
630 ForcedShellFunctions = 0x000800, // Only functions that are overridden to be implemented in the shell class
631 WasPublic = 0x001000, // Only functions that were originally public
632 WasProtected = 0x002000, // Only functions that were originally protected
633 NonStaticFunctions = 0x004000, // No static functions
634 Empty = 0x008000, // Empty overrides of abstract functions
635 Invisible = 0x010000, // Only private functions
636 VirtualInCppFunctions = 0x020000, // Only functions that are virtual in C++
637 NonEmptyFunctions = 0x040000, // Only functions with JNI implementations
638 VirtualInTargetLangFunctions = 0x080000, // Only functions which are virtual in TargetLang
639 AbstractFunctions = 0x100000, // Only abstract functions
640 WasVisible = 0x200000, // Only functions that were public or protected in the original code
641 NotRemovedFromTargetLang = 0x400000, // Only functions that have not been removed from TargetLang
642 NotRemovedFromShell = 0x800000, // Only functions that have not been removed from the shell class
643 VirtualSlots = 0x1000000 // Only functions that are set as virtual slots in the type system
646 AbstractMetaClass()
647 : m_namespace(false),
648 m_qobject(false),
649 m_has_virtuals(false),
650 m_has_nonpublic(false),
651 m_has_virtual_slots(false),
652 m_has_nonprivateconstructor(false),
653 m_functions_fixed(false),
654 m_has_public_destructor(true),
655 m_force_shell_class(false),
656 m_has_hash_function(false),
657 m_has_equals_operator(false),
658 m_has_clone_operator(false),
659 m_is_type_alias(false),
660 m_enclosing_class(0),
661 m_base_class(0),
662 m_template_base_class(0),
663 m_extracted_interface(0),
664 m_primary_interface_implementor(0),
665 m_type_entry(0),
666 m_qDebug_stream_function(0)
670 virtual ~AbstractMetaClass();
672 AbstractMetaClass *extractInterface();
673 void fixFunctions();
675 AbstractMetaFunctionList functions() const { return m_functions; }
676 void setFunctions(const AbstractMetaFunctionList &functions);
677 void addFunction(AbstractMetaFunction *function);
678 bool hasFunction(const AbstractMetaFunction *f) const;
679 bool hasFunction(const QString &str) const;
680 bool hasSignal(const AbstractMetaFunction *f) const;
682 bool hasConstructors() const;
684 void addDefaultConstructor();
686 bool hasNonPrivateConstructor() const { return m_has_nonprivateconstructor; }
687 void setHasNonPrivateConstructor(bool on) { m_has_nonprivateconstructor = on; }
688 bool hasPublicDestructor() const { return m_has_public_destructor; }
689 void setHasPublicDestructor(bool on) { m_has_public_destructor = on; }
691 AbstractMetaFunctionList queryFunctionsByName(const QString &name) const;
692 AbstractMetaFunctionList queryFunctions(uint query) const;
693 inline AbstractMetaFunctionList allVirtualFunctions() const;
694 inline AbstractMetaFunctionList allFinalFunctions() const;
695 AbstractMetaFunctionList functionsInTargetLang() const;
696 AbstractMetaFunctionList functionsInShellClass() const;
697 inline AbstractMetaFunctionList cppInconsistentFunctions() const;
698 inline AbstractMetaFunctionList cppSignalFunctions() const;
699 AbstractMetaFunctionList publicOverrideFunctions() const;
700 AbstractMetaFunctionList virtualOverrideFunctions() const;
701 AbstractMetaFunctionList virtualFunctions() const;
702 AbstractMetaFunctionList nonVirtualShellFunctions() const;
704 AbstractMetaFieldList fields() const { return m_fields; }
705 void setFields(const AbstractMetaFieldList &fields) { m_fields = fields; }
706 void addField(AbstractMetaField *field) { m_fields << field; }
708 AbstractMetaEnumList enums() const { return m_enums; }
709 void setEnums(const AbstractMetaEnumList &enums) { m_enums = enums; }
710 void addEnum(AbstractMetaEnum *e) { m_enums << e; }
712 AbstractMetaEnum *findEnum(const QString &enumName);
713 AbstractMetaEnum *findEnumForValue(const QString &enumName);
714 AbstractMetaEnumValue *findEnumValue(const QString &enumName, AbstractMetaEnum *meta_enum);
716 AbstractMetaClassList interfaces() const { return m_interfaces; }
717 void addInterface(AbstractMetaClass *interface);
718 void setInterfaces(const AbstractMetaClassList &interface);
720 QString fullName() const { return package() + "." + name(); }
721 QString name() const;
723 QString baseClassName() const { return m_base_class ? m_base_class->name() : QString(); }
725 AbstractMetaClass *baseClass() const { return m_base_class; }
726 void setBaseClass(AbstractMetaClass *base_class) { m_base_class = base_class; }
728 const AbstractMetaClass *enclosingClass() const { return m_enclosing_class; }
729 void setEnclosingClass(AbstractMetaClass *cl) { m_enclosing_class = cl; }
731 QString package() const { return m_type_entry->javaPackage(); }
732 bool isInterface() const { return m_type_entry->isInterface(); }
733 bool isNamespace() const { return m_type_entry->isNamespace(); }
734 bool isQObject() const { return m_type_entry->isQObject(); }
735 bool isQtNamespace() const { return isNamespace() && name() == "Qt"; }
736 QString qualifiedCppName() const { return m_type_entry->qualifiedCppName(); }
738 bool hasInconsistentFunctions() const;
739 bool hasSignals() const;
740 bool inheritsFrom(const AbstractMetaClass *other) const;
742 void setForceShellClass(bool on) { m_force_shell_class = on; }
743 bool generateShellClass() const;
745 bool hasVirtualSlots() const { return m_has_virtual_slots; }
746 bool hasVirtualFunctions() const { return !isFinal() && m_has_virtuals; }
747 bool hasProtectedFunctions() const;
749 QList<TypeEntry *> templateArguments() const { return m_template_args; }
750 void setTemplateArguments(const QList<TypeEntry *> &args) { m_template_args = args; }
752 bool hasFieldAccessors() const;
754 // only valid during metajavabuilder's run
755 QStringList baseClassNames() const { return m_base_class_names; }
756 void setBaseClassNames(const QStringList &names) { m_base_class_names = names; }
758 AbstractMetaClass *primaryInterfaceImplementor() const { return m_primary_interface_implementor; }
759 void setPrimaryInterfaceImplementor(AbstractMetaClass *cl) { m_primary_interface_implementor = cl; }
761 const ComplexTypeEntry *typeEntry() const { return m_type_entry; }
762 ComplexTypeEntry *typeEntry() { return m_type_entry; }
763 void setTypeEntry(ComplexTypeEntry *type) { m_type_entry = type; }
765 void setHasHashFunction(bool on) { m_has_hash_function = on; }
766 bool hasHashFunction() const { return m_has_hash_function; }
768 void setToStringCapability(FunctionModelItem fun) { m_qDebug_stream_function= fun; }
769 FunctionModelItem hasToStringCapability() const { return m_qDebug_stream_function; }
771 virtual bool hasDefaultToStringFunction() const;
773 void setHasEqualsOperator(bool on) { m_has_equals_operator = on; }
774 bool hasEqualsOperator() const { return m_has_equals_operator; }
776 void setHasCloneOperator(bool on) { m_has_clone_operator = on; }
777 bool hasCloneOperator() const { return m_has_clone_operator; }
779 void addPropertySpec(QPropertySpec *spec) { m_property_specs << spec; }
780 QList<QPropertySpec *> propertySpecs() const { return m_property_specs; }
782 QPropertySpec *propertySpecForRead(const QString &name) const;
783 QPropertySpec *propertySpecForWrite(const QString &name) const;
784 QPropertySpec *propertySpecForReset(const QString &name) const;
786 QList<ReferenceCount> referenceCounts() const;
788 void setEqualsFunctions(const AbstractMetaFunctionList &lst) { m_equals_functions = lst; }
789 AbstractMetaFunctionList equalsFunctions() const { return m_equals_functions; }
791 void setNotEqualsFunctions(const AbstractMetaFunctionList &lst) { m_nequals_functions = lst; }
792 AbstractMetaFunctionList notEqualsFunctions() const { return m_nequals_functions; }
794 void setLessThanFunctions(const AbstractMetaFunctionList &lst) { m_less_than_functions = lst; }
795 AbstractMetaFunctionList lessThanFunctions() const { return m_less_than_functions; }
797 void setGreaterThanFunctions(const AbstractMetaFunctionList &lst) { m_greater_than_functions = lst; }
798 AbstractMetaFunctionList greaterThanFunctions() const { return m_greater_than_functions; }
800 void setLessThanEqFunctions(const AbstractMetaFunctionList &lst) { m_less_than_eq_functions = lst; }
801 AbstractMetaFunctionList lessThanEqFunctions() const { return m_less_than_eq_functions; }
803 void setGreaterThanEqFunctions(const AbstractMetaFunctionList &lst) { m_greater_than_eq_functions = lst; }
804 AbstractMetaFunctionList greaterThanEqFunctions() const { return m_greater_than_eq_functions; }
806 void sortFunctions();
808 const AbstractMetaClass *templateBaseClass() const { return m_template_base_class; }
809 void setTemplateBaseClass(const AbstractMetaClass *cls) { m_template_base_class = cls; }
811 void setTypeAlias(bool typeAlias) { m_is_type_alias = typeAlias; }
812 bool isTypeAlias() const { return m_is_type_alias; }
814 private:
815 uint m_namespace : 1;
816 uint m_qobject : 1;
817 uint m_has_virtuals : 1;
818 uint m_has_nonpublic : 1;
819 uint m_has_virtual_slots : 1;
820 uint m_has_nonprivateconstructor : 1;
821 uint m_functions_fixed : 1;
822 uint m_has_public_destructor : 1;
823 uint m_force_shell_class : 1;
824 uint m_has_hash_function : 1;
825 uint m_has_equals_operator : 1;
826 uint m_has_clone_operator :1;
827 uint m_is_type_alias : 1;
828 uint m_reserved : 19;
830 const AbstractMetaClass *m_enclosing_class;
831 AbstractMetaClass *m_base_class;
832 const AbstractMetaClass *m_template_base_class;
833 AbstractMetaFunctionList m_functions;
834 AbstractMetaFieldList m_fields;
835 AbstractMetaEnumList m_enums;
836 AbstractMetaClassList m_interfaces;
837 AbstractMetaClass *m_extracted_interface;
838 AbstractMetaClass *m_primary_interface_implementor;
839 QList<QPropertySpec *> m_property_specs;
840 AbstractMetaFunctionList m_equals_functions;
841 AbstractMetaFunctionList m_nequals_functions;
843 AbstractMetaFunctionList m_less_than_functions;
844 AbstractMetaFunctionList m_greater_than_functions;
845 AbstractMetaFunctionList m_less_than_eq_functions;
846 AbstractMetaFunctionList m_greater_than_eq_functions;
848 QStringList m_base_class_names;
849 QList<TypeEntry *> m_template_args;
850 ComplexTypeEntry *m_type_entry;
851 FunctionModelItem m_qDebug_stream_function;
854 class QPropertySpec {
855 public:
856 QPropertySpec(const TypeEntry *type)
857 : m_type(type),
858 m_index(-1)
862 const TypeEntry *type() const { return m_type; }
864 QString name() const { return m_name; }
865 void setName(const QString &name) { m_name = name; }
867 QString read() const { return m_read; }
868 void setRead(const QString &read) { m_read = read; }
870 QString write() const { return m_write; }
871 void setWrite(const QString &write) { m_write = write; }
873 QString designable() const { return m_designable; }
874 void setDesignable(const QString &designable) { m_designable = designable; }
876 QString reset() const { return m_reset; }
877 void setReset(const QString &reset) { m_reset = reset; }
879 int index() const { return m_index; }
880 void setIndex(int index) { m_index = index; }
882 private:
883 QString m_name;
884 QString m_read;
885 QString m_write;
886 QString m_designable;
887 QString m_reset;
888 const TypeEntry *m_type;
889 int m_index;
892 inline AbstractMetaFunctionList AbstractMetaClass::allVirtualFunctions() const
894 return queryFunctions(VirtualFunctions
895 | NotRemovedFromTargetLang);
898 inline AbstractMetaFunctionList AbstractMetaClass::allFinalFunctions() const
900 return queryFunctions(FinalInTargetLangFunctions
901 | FinalInCppFunctions
902 | NotRemovedFromTargetLang);
905 inline AbstractMetaFunctionList AbstractMetaClass::cppInconsistentFunctions() const
907 return queryFunctions(Inconsistent
908 | NormalFunctions
909 | Visible
910 | NotRemovedFromTargetLang);
913 inline AbstractMetaFunctionList AbstractMetaClass::cppSignalFunctions() const
915 return queryFunctions(Signals
916 | Visible
917 | NotRemovedFromTargetLang);
920 #endif // ABSTRACTMETALANG_H