comparison generator/abstractmetalang.h @ 1:e78566595089

initial import
author mandel
date Mon, 11 May 2009 16:01:50 +0000
parents
children eb3b5bbffc8f
comparison
equal deleted inserted replaced
0:36fb74dc547d 1:e78566595089
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
443 QString minimalSignature() const;
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),
698 m_qDebug_stream_function(0)
699 {
700 }
701
702 virtual ~AbstractMetaClass();
703
704 AbstractMetaClass *extractInterface();
705 void fixFunctions();
706
707 AbstractMetaFunctionList functions() const { return m_functions; }
708 void setFunctions(const AbstractMetaFunctionList &functions);
709 void addFunction(AbstractMetaFunction *function);
710 bool hasFunction(const AbstractMetaFunction *f) const;
711 bool hasFunction(const QString &str) const;
712 bool hasSignal(const AbstractMetaFunction *f) const;
713
714 bool hasConstructors() const;
715
716 void addDefaultConstructor();
717
718 bool hasNonPrivateConstructor() const { return m_has_nonprivateconstructor; }
719 void setHasNonPrivateConstructor(bool on) { m_has_nonprivateconstructor = on; }
720 bool hasPublicDestructor() const { return m_has_public_destructor; }
721 void setHasPublicDestructor(bool on) { m_has_public_destructor = on; }
722
723 AbstractMetaFunctionList queryFunctionsByName(const QString &name) const;
724 AbstractMetaFunctionList queryFunctions(uint query) const;
725 inline AbstractMetaFunctionList allVirtualFunctions() const;
726 inline AbstractMetaFunctionList allFinalFunctions() const;
727 AbstractMetaFunctionList functionsInTargetLang() const;
728 AbstractMetaFunctionList functionsInShellClass() const;
729 inline AbstractMetaFunctionList cppInconsistentFunctions() const;
730 inline AbstractMetaFunctionList cppSignalFunctions() const;
731 AbstractMetaFunctionList publicOverrideFunctions() const;
732 AbstractMetaFunctionList virtualOverrideFunctions() const;
733 AbstractMetaFunctionList virtualFunctions() const;
734 AbstractMetaFunctionList nonVirtualShellFunctions() const;
735
736 AbstractMetaFieldList fields() const { return m_fields; }
737 void setFields(const AbstractMetaFieldList &fields) { m_fields = fields; }
738 void addField(AbstractMetaField *field) { m_fields << field; }
739
740 AbstractMetaEnumList enums() const { return m_enums; }
741 void setEnums(const AbstractMetaEnumList &enums) { m_enums = enums; }
742 void addEnum(AbstractMetaEnum *e) { m_enums << e; }
743
744 AbstractMetaEnum *findEnum(const QString &enumName);
745 AbstractMetaEnum *findEnumForValue(const QString &enumName);
746 AbstractMetaEnumValue *findEnumValue(const QString &enumName, AbstractMetaEnum *meta_enum);
747
748 AbstractMetaClassList interfaces() const { return m_interfaces; }
749 void addInterface(AbstractMetaClass *interface);
750 void setInterfaces(const AbstractMetaClassList &interface);
751
752 QString fullName() const { return package() + "." + name(); }
753 QString name() const;
754
755 QString baseClassName() const { return m_base_class ? m_base_class->name() : QString(); }
756
757 AbstractMetaClass *baseClass() const { return m_base_class; }
758 void setBaseClass(AbstractMetaClass *base_class) { m_base_class = base_class; }
759
760 const AbstractMetaClass *enclosingClass() const { return m_enclosing_class; }
761 void setEnclosingClass(AbstractMetaClass *cl) { m_enclosing_class = cl; }
762
763 QString package() const { return m_type_entry->javaPackage(); }
764 bool isInterface() const { return m_type_entry->isInterface(); }
765 bool isNamespace() const { return m_type_entry->isNamespace(); }
766 bool isQObject() const { return m_type_entry->isQObject(); }
767 bool isQtNamespace() const { return isNamespace() && name() == "Qt"; }
768 QString qualifiedCppName() const { return m_type_entry->qualifiedCppName(); }
769
770 bool hasInconsistentFunctions() const;
771 bool hasSignals() const;
772 bool inheritsFrom(const AbstractMetaClass *other) const;
773
774 void setForceShellClass(bool on) { m_force_shell_class = on; }
775 bool generateShellClass() const;
776
777 bool hasVirtualSlots() const { return m_has_virtual_slots; }
778 bool hasVirtualFunctions() const { return !isFinal() && m_has_virtuals; }
779 bool hasProtectedFunctions() const;
780
781 QList<TypeEntry *> templateArguments() const { return m_template_args; }
782 void setTemplateArguments(const QList<TypeEntry *> &args) { m_template_args = args; }
783
784 bool hasFieldAccessors() const;
785
786 // only valid during metajavabuilder's run
787 QStringList baseClassNames() const { return m_base_class_names; }
788 void setBaseClassNames(const QStringList &names) { m_base_class_names = names; }
789
790 AbstractMetaClass *primaryInterfaceImplementor() const { return m_primary_interface_implementor; }
791 void setPrimaryInterfaceImplementor(AbstractMetaClass *cl) { m_primary_interface_implementor = cl; }
792
793 const ComplexTypeEntry *typeEntry() const { return m_type_entry; }
794 ComplexTypeEntry *typeEntry() { return m_type_entry; }
795 void setTypeEntry(ComplexTypeEntry *type) { m_type_entry = type; }
796
797 void setHasHashFunction(bool on) { m_has_hash_function = on; }
798 bool hasHashFunction() const { return m_has_hash_function; }
799
800 void setToStringCapability(FunctionModelItem fun) { m_qDebug_stream_function= fun; }
801 FunctionModelItem hasToStringCapability() const { return m_qDebug_stream_function; }
802
803 virtual bool hasDefaultToStringFunction() const;
804
805 void setHasEqualsOperator(bool on) { m_has_equals_operator = on; }
806 bool hasEqualsOperator() const { return m_has_equals_operator; }
807
808 void setHasCloneOperator(bool on) { m_has_clone_operator = on; }
809 bool hasCloneOperator() const { return m_has_clone_operator; }
810
811 void addPropertySpec(QPropertySpec *spec) { m_property_specs << spec; }
812 QList<QPropertySpec *> propertySpecs() const { return m_property_specs; }
813
814 QPropertySpec *propertySpecForRead(const QString &name) const;
815 QPropertySpec *propertySpecForWrite(const QString &name) const;
816 QPropertySpec *propertySpecForReset(const QString &name) const;
817
818 QList<ReferenceCount> referenceCounts() const;
819
820 void setEqualsFunctions(const AbstractMetaFunctionList &lst) { m_equals_functions = lst; }
821 AbstractMetaFunctionList equalsFunctions() const { return m_equals_functions; }
822
823 void setNotEqualsFunctions(const AbstractMetaFunctionList &lst) { m_nequals_functions = lst; }
824 AbstractMetaFunctionList notEqualsFunctions() const { return m_nequals_functions; }
825
826 void setLessThanFunctions(const AbstractMetaFunctionList &lst) { m_less_than_functions = lst; }
827 AbstractMetaFunctionList lessThanFunctions() const { return m_less_than_functions; }
828
829 void setGreaterThanFunctions(const AbstractMetaFunctionList &lst) { m_greater_than_functions = lst; }
830 AbstractMetaFunctionList greaterThanFunctions() const { return m_greater_than_functions; }
831
832 void setLessThanEqFunctions(const AbstractMetaFunctionList &lst) { m_less_than_eq_functions = lst; }
833 AbstractMetaFunctionList lessThanEqFunctions() const { return m_less_than_eq_functions; }
834
835 void setGreaterThanEqFunctions(const AbstractMetaFunctionList &lst) { m_greater_than_eq_functions = lst; }
836 AbstractMetaFunctionList greaterThanEqFunctions() const { return m_greater_than_eq_functions; }
837
838 void sortFunctions();
839
840 const AbstractMetaClass *templateBaseClass() const { return m_template_base_class; }
841 void setTemplateBaseClass(const AbstractMetaClass *cls) { m_template_base_class = cls; }
842
843 void setTypeAlias(bool typeAlias) { m_is_type_alias = typeAlias; }
844 bool isTypeAlias() const { return m_is_type_alias; }
845
846 private:
847 uint m_namespace : 1;
848 uint m_qobject : 1;
849 uint m_has_virtuals : 1;
850 uint m_has_nonpublic : 1;
851 uint m_has_virtual_slots : 1;
852 uint m_has_nonprivateconstructor : 1;
853 uint m_functions_fixed : 1;
854 uint m_has_public_destructor : 1;
855 uint m_force_shell_class : 1;
856 uint m_has_hash_function : 1;
857 uint m_has_equals_operator : 1;
858 uint m_has_clone_operator :1;
859 uint m_is_type_alias : 1;
860 uint m_reserved : 19;
861
862 const AbstractMetaClass *m_enclosing_class;
863 AbstractMetaClass *m_base_class;
864 const AbstractMetaClass *m_template_base_class;
865 AbstractMetaFunctionList m_functions;
866 AbstractMetaFieldList m_fields;
867 AbstractMetaEnumList m_enums;
868 AbstractMetaClassList m_interfaces;
869 AbstractMetaClass *m_extracted_interface;
870 AbstractMetaClass *m_primary_interface_implementor;
871 QList<QPropertySpec *> m_property_specs;
872 AbstractMetaFunctionList m_equals_functions;
873 AbstractMetaFunctionList m_nequals_functions;
874
875 AbstractMetaFunctionList m_less_than_functions;
876 AbstractMetaFunctionList m_greater_than_functions;
877 AbstractMetaFunctionList m_less_than_eq_functions;
878 AbstractMetaFunctionList m_greater_than_eq_functions;
879
880 QStringList m_base_class_names;
881 QList<TypeEntry *> m_template_args;
882 ComplexTypeEntry *m_type_entry;
883 FunctionModelItem m_qDebug_stream_function;
884
885 // qtd2 hack
886 friend class DGenerator;
887 };
888
889 class QPropertySpec {
890 public:
891 QPropertySpec(const TypeEntry *type)
892 : m_type(type),
893 m_index(-1)
894 {
895 }
896
897 const TypeEntry *type() const { return m_type; }
898
899 QString name() const { return m_name; }
900 void setName(const QString &name) { m_name = name; }
901
902 QString read() const { return m_read; }
903 void setRead(const QString &read) { m_read = read; }
904
905 QString write() const { return m_write; }
906 void setWrite(const QString &write) { m_write = write; }
907
908 QString designable() const { return m_designable; }
909 void setDesignable(const QString &designable) { m_designable = designable; }
910
911 QString reset() const { return m_reset; }
912 void setReset(const QString &reset) { m_reset = reset; }
913
914 int index() const { return m_index; }
915 void setIndex(int index) { m_index = index; }
916
917 private:
918 QString m_name;
919 QString m_read;
920 QString m_write;
921 QString m_designable;
922 QString m_reset;
923 const TypeEntry *m_type;
924 int m_index;
925 };
926
927 // qtd
928 class ArgumentReplace
929 {
930 private:
931 QHash<QString, QString> data;
932 static ArgumentReplace *m_instance;
933 ArgumentReplace();
934
935 public:
936 static void init();
937 static QString translate(QString arg);
938 };
939
940 inline AbstractMetaFunctionList AbstractMetaClass::allVirtualFunctions() const
941 {
942 return queryFunctions(VirtualFunctions
943 | NotRemovedFromTargetLang);
944 }
945
946 inline AbstractMetaFunctionList AbstractMetaClass::allFinalFunctions() const
947 {
948 return queryFunctions(FinalInTargetLangFunctions
949 | FinalInCppFunctions
950 | NotRemovedFromTargetLang);
951 }
952
953 inline AbstractMetaFunctionList AbstractMetaClass::cppInconsistentFunctions() const
954 {
955 return queryFunctions(Inconsistent
956 | NormalFunctions
957 | Visible
958 | NotRemovedFromTargetLang);
959 }
960
961 inline AbstractMetaFunctionList AbstractMetaClass::cppSignalFunctions() const
962 {
963 return queryFunctions(Signals
964 | Visible
965 | NotRemovedFromTargetLang);
966 }
967
968 #endif // ABSTRACTMETALANG_H