1 /****************************************************************************
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
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 ****************************************************************************/
27 #include <QtCore/QHash>
28 #include <QtCore/QString>
29 #include <QtCore/QStringList>
30 #include <QtCore/QMap>
35 class AbstractMetaType
;
41 extern QString strings_Object
;
42 extern QString strings_String
;
43 extern QString strings_Thread
;
44 extern QString strings_char
;
45 extern QString strings_java_lang
;
46 extern QString strings_jchar
;
47 extern QString strings_jobject
;
57 Include() : type(IncludePath
) { }
58 Include(IncludeType t
, const QString
&nam
) : type(t
), name(nam
) { };
60 bool isValid() { return !name
.isEmpty(); }
65 QString
toString() const;
67 bool operator<(const Include
&other
) const { return name
< other
.name
; }
69 typedef QList
<Include
> IncludeList
;
71 typedef QMap
<int, QString
> ArgumentMap
;
73 class TemplateInstance
;
75 namespace TypeSystem
{
78 TargetLangCode
= 0x0001,
81 ShellDeclaration
= 0x0008,
82 PackageInitializer
= 0x0010,
83 DestructorFunction
= 0x0020,
84 Constructors
= 0x0040,
97 JavaAndNativeCode
= TargetLangCode
| NativeCode
,
98 TargetLangAndNativeCode
= TargetLangCode
| NativeCode
109 struct ReferenceCount
111 ReferenceCount() : threadSafe(false), access(Public
) { }
112 enum Action
{ // 0x01 - 0xff
125 enum Flag
{ // 0x100 - 0xf00
128 DeclareVariable
= 0x400,
133 enum Access
{ // 0x1000 - 0xf000
143 QString variableName
;
145 QString declareVariable
;
152 class CodeSnipFragment
{
154 const QString m_code
;
155 TemplateInstance
*m_instance
;
158 CodeSnipFragment(const QString
&code
)
163 CodeSnipFragment(TemplateInstance
*instance
)
164 : m_instance(instance
)
167 QString
code() const;
170 class CodeSnipAbstract
{
172 QString
code() const;
174 void addCode(const QString
&code
){
175 codeList
.append(new CodeSnipFragment(code
));
178 void addTemplateInstance(TemplateInstance
*ti
){
179 codeList
.append(new CodeSnipFragment(ti
));
182 QList
<CodeSnipFragment
*> codeList
;
185 class CustomFunction
: public CodeSnipAbstract
188 CustomFunction(const QString
&n
= QString()) : name(n
) { }
194 class TemplateEntry
: public CodeSnipAbstract
197 TemplateEntry(const QString
&name
)
202 QString
name() const {
210 typedef QHash
<QString
, TemplateEntry
*> TemplateEntryHash
;
212 class TemplateInstance
215 TemplateInstance(const QString
&name
)
219 void addReplaceRule(const QString
&name
, const QString
&value
){
220 replaceRules
[name
]=value
;
223 QString
expandCode() const;
225 QString
name() const {
230 const QString m_name
;
231 QHash
<QString
, QString
> replaceRules
;
235 class CodeSnip
: public CodeSnipAbstract
243 PrototypeInitialization
,
244 ConstructorInitialization
,
248 CodeSnip() : language(TypeSystem::TargetLangCode
) { }
249 CodeSnip(TypeSystem::Language lang
) : language(lang
) { }
251 // Very simple, easy to make code ugly if you try
252 QTextStream
&formattedCode(QTextStream
&s
, Indentor
&indentor
) const;
254 TypeSystem::Language language
;
256 ArgumentMap argumentMap
;
258 typedef QList
<CodeSnip
> CodeSnipList
;
260 struct ArgumentModification
262 ArgumentModification(int idx
) : removed_default_expression(false), removed(false), no_null_pointers(false), index(idx
)
265 // Should the default expression be removed?
266 uint removed_default_expression
: 1;
268 uint no_null_pointers
: 1;
269 uint reset_after_use
: 1;
271 // The index of this argument
274 // Reference count flags for this argument
275 QList
<ReferenceCount
> referenceCounts
;
277 // The text given for the new type of the argument
278 QString modified_type
;
280 QString replace_value
;
282 // The code to be used to construct a return value when no_null_pointers is true and
283 // the returned value is null. If no_null_pointers is true and this string is
284 // empty, then the base class implementation will be used (or a default construction
285 // if there is no implementation)
286 QString null_pointer_default_value
;
288 // The text of the new default expression of the argument
289 QString replaced_default_expression
;
291 // The new definition of ownership for a specific argument
292 QHash
<TypeSystem::Language
, TypeSystem::Ownership
> ownerships
;
294 // Different conversion rules
295 CodeSnipList conversion_rules
;
298 struct Modification
{
304 AccessModifierMask
= 0x000f,
308 FinalMask
= Final
| NonFinal
,
313 CodeInjection
= 0x1000,
316 ReplaceExpression
= 0x8000,
317 VirtualSlot
= 0x10000 | NonFinal
320 Modification() : modifiers(0) { }
322 bool isAccessModifier() const { return modifiers
& AccessModifierMask
; }
323 Modifiers
accessModifier() const { return Modifiers(modifiers
& AccessModifierMask
); }
324 bool isPrivate() const { return accessModifier() == Private
; }
325 bool isProtected() const { return accessModifier() == Protected
; }
326 bool isPublic() const { return accessModifier() == Public
; }
327 bool isFriendly() const { return accessModifier() == Friendly
; }
328 bool isFinal() const { return modifiers
& Final
; }
329 bool isNonFinal() const { return modifiers
& NonFinal
; }
330 bool isVirtualSlot() const { return (modifiers
& VirtualSlot
) == VirtualSlot
; }
331 QString
accessModifierString() const;
333 bool isDeprecated() const { return modifiers
& Deprecated
; }
335 void setRenamedTo(const QString
&name
) { renamedToName
= name
; }
336 QString
renamedTo() const { return renamedToName
; }
337 bool isRenameModifier() const { return modifiers
& Rename
; }
340 QString renamedToName
;
343 struct FunctionModification
: public Modification
345 FunctionModification() : removal(TypeSystem::NoLanguage
) { }
347 bool isCodeInjection() const { return modifiers
& CodeInjection
; }
348 bool isRemoveModifier() const { return removal
!= TypeSystem::NoLanguage
; }
350 QString
toString() const;
355 TypeSystem::Language removal
;
357 QList
<ArgumentModification
> argument_mods
;
359 typedef QList
<FunctionModification
> FunctionModificationList
;
361 struct FieldModification
: public Modification
363 bool isReadable() const { return modifiers
& Readable
; }
364 bool isWritable() const { return modifiers
& Writable
; }
368 typedef QList
<FieldModification
> FieldModificationList
;
370 struct ExpensePolicy
{
371 ExpensePolicy() : limit(-1) { }
374 bool isValid() const { return limit
>= 0; }
377 class InterfaceTypeEntry
;
378 class ObjectTypeEntry
;
388 TemplateArgumentType
,
404 enum CodeGeneration
{
405 GenerateTargetLang
= 0x0001,
406 GenerateCpp
= 0x0002,
407 GenerateForSubclass
= 0x0004,
410 GenerateAll
= 0xffff,
411 GenerateCode
= GenerateTargetLang
| GenerateCpp
414 TypeEntry(const QString
&name
, Type t
)
417 m_code_generation(GenerateAll
),
418 m_preferred_conversion(true)
422 virtual ~TypeEntry() { }
424 Type
type() const { return m_type
; }
425 bool isPrimitive() const { return m_type
== PrimitiveType
; }
426 bool isEnum() const { return m_type
== EnumType
; }
427 bool isFlags() const { return m_type
== FlagsType
; }
428 bool isInterface() const { return m_type
== InterfaceType
; }
429 bool isObject() const { return m_type
== ObjectType
; }
430 bool isString() const { return m_type
== StringType
; }
431 bool isChar() const { return m_type
== CharType
; }
432 bool isNamespace() const { return m_type
== NamespaceType
; }
433 bool isContainer() const { return m_type
== ContainerType
; }
434 bool isVariant() const { return m_type
== VariantType
; }
435 bool isJObjectWrapper() const { return m_type
== JObjectWrapperType
; }
436 bool isArray() const { return m_type
== ArrayType
; }
437 bool isTemplateArgument() const { return m_type
== TemplateArgumentType
; }
438 bool isVoid() const { return m_type
== VoidType
; }
439 bool isThread() const { return m_type
== ThreadType
; }
440 bool isCustom() const { return m_type
== CustomType
; }
441 bool isBasicValue() const { return m_type
== BasicValueType
; }
442 bool isTypeSystem() const { return m_type
== TypeSystemType
; }
444 virtual bool preferredConversion() const { return m_preferred_conversion
; }
445 virtual void setPreferredConversion(bool b
) { m_preferred_conversion
= b
; }
447 // The type's name in C++, fully qualified
448 QString
name() const { return m_name
; }
450 uint
codeGeneration() const { return m_code_generation
; }
451 void setCodeGeneration(uint cg
) { m_code_generation
= cg
; }
453 virtual QString
qualifiedCppName() const { return m_name
; }
455 // Its type's name in JNI
456 virtual QString
jniName() const { return m_name
; }
458 // The type's name in TargetLang
459 virtual QString
targetLangName() const { return m_name
; }
461 // The type to lookup when converting to TargetLang
462 virtual QString
lookupName() const { return targetLangName(); }
465 virtual QString
javaPackage() const { return QString(); }
467 virtual QString
qualifiedTargetLangName() const {
468 QString pkg
= javaPackage();
469 if (pkg
.isEmpty()) return targetLangName();
470 return pkg
+ '.' + targetLangName();
473 virtual InterfaceTypeEntry
*designatedInterface() const { return 0; }
475 void setCustomConstructor(const CustomFunction
&func
) { m_customConstructor
= func
; }
476 CustomFunction
customConstructor() const { return m_customConstructor
; }
478 void setCustomDestructor(const CustomFunction
&func
) { m_customDestructor
= func
; }
479 CustomFunction
customDestructor() const { return m_customDestructor
; }
481 virtual bool isValue() const { return false; }
482 virtual bool isComplex() const { return false; }
484 virtual bool isNativeIdBased() const { return false; }
489 uint m_code_generation
;
490 CustomFunction m_customConstructor
;
491 CustomFunction m_customDestructor
;
492 bool m_preferred_conversion
;
494 typedef QHash
<QString
, QList
<TypeEntry
*> > TypeEntryHash
;
495 typedef QHash
<QString
, TypeEntry
*> SingleTypeEntryHash
;
498 class TypeSystemTypeEntry
: public TypeEntry
501 TypeSystemTypeEntry(const QString
&name
)
502 : TypeEntry(name
, TypeSystemType
)
506 QList
<CodeSnip
> snips
;
510 class ThreadTypeEntry
: public TypeEntry
513 ThreadTypeEntry() : TypeEntry("QThread", ThreadType
) { setCodeGeneration(GenerateNothing
); }
515 QString
jniName() const { return strings_jobject
; }
516 QString
targetLangName() const { return strings_Thread
; }
517 QString
javaPackage() const { return strings_java_lang
; }
520 class VoidTypeEntry
: public TypeEntry
523 VoidTypeEntry() : TypeEntry("void", VoidType
) { }
526 class TemplateArgumentEntry
: public TypeEntry
529 TemplateArgumentEntry(const QString
&name
)
530 : TypeEntry(name
, TemplateArgumentType
), m_ordinal(0)
534 int ordinal() const { return m_ordinal
; }
535 void setOrdinal(int o
) { m_ordinal
= o
; }
541 class ArrayTypeEntry
: public TypeEntry
544 ArrayTypeEntry(const TypeEntry
*nested_type
) : TypeEntry("Array", ArrayType
), m_nested_type(nested_type
)
546 Q_ASSERT(m_nested_type
);
549 void setNestedTypeEntry(TypeEntry
*nested
) { m_nested_type
= nested
; }
550 const TypeEntry
*nestedTypeEntry() const { return m_nested_type
; }
552 QString
targetLangName() const { return m_nested_type
->targetLangName() + "[]"; }
553 QString
jniName() const
555 if (m_nested_type
->isPrimitive())
556 return m_nested_type
->jniName() + "Array";
558 return "jobjectArray";
562 const TypeEntry
*m_nested_type
;
566 class PrimitiveTypeEntry
: public TypeEntry
569 PrimitiveTypeEntry(const QString
&name
)
570 : TypeEntry(name
, PrimitiveType
), m_preferred_conversion(true), m_preferred_java_type(true)
574 QString
targetLangName() const { return m_java_name
; }
575 void setTargetLangName(const QString
&targetLangName
) { m_java_name
= targetLangName
; }
577 QString
jniName() const { return m_jni_name
; }
578 void setJniName(const QString
&jniName
) { m_jni_name
= jniName
; }
580 QString
javaObjectFullName() const { return javaObjectPackage() + "." + javaObjectName(); }
581 QString
javaObjectName() const;
582 QString
javaObjectPackage() const { return strings_java_lang
; }
584 virtual bool preferredConversion() const { return m_preferred_conversion
; }
585 virtual void setPreferredConversion(bool b
) { m_preferred_conversion
= b
; }
587 virtual bool preferredTargetLangType() const { return m_preferred_java_type
; }
588 virtual void setPreferredTargetLangType(bool b
) { m_preferred_java_type
= b
; }
593 uint m_preferred_conversion
: 1;
594 uint m_preferred_java_type
: 1;
600 struct EnumValueRedirection
602 EnumValueRedirection(const QString
&rej
, const QString
&us
)
611 class EnumTypeEntry
: public TypeEntry
614 EnumTypeEntry(const QString
&nspace
, const QString
&enumName
)
615 : TypeEntry(nspace
.isEmpty() ? enumName
: nspace
+ QLatin1String("::") + enumName
,
620 m_qualifier
= nspace
;
621 m_java_name
= enumName
;
624 QString
javaPackage() const { return m_package_name
; }
625 void setTargetLangPackage(const QString
&package
) { m_package_name
= package
; }
627 QString
targetLangName() const { return m_java_name
; }
628 QString
javaQualifier() const;
629 QString
qualifiedTargetLangName() const {
630 QString pkg
= javaPackage();
631 if (pkg
.isEmpty()) return javaQualifier() + '.' + targetLangName();
632 return pkg
+ '.' + javaQualifier() + '.' + targetLangName();
635 QString
jniName() const;
637 QString
qualifier() const { return m_qualifier
; }
638 void setQualifier(const QString
&q
) { m_qualifier
= q
; }
640 virtual bool preferredConversion() const { return false; }
642 bool isBoundsChecked() const { return m_lower_bound
.isEmpty() && m_upper_bound
.isEmpty(); }
644 QString
upperBound() const { return m_upper_bound
; }
645 void setUpperBound(const QString
&bound
) { m_upper_bound
= bound
; }
647 QString
lowerBound() const { return m_lower_bound
; }
648 void setLowerBound(const QString
&bound
) { m_lower_bound
= bound
; }
650 void setFlags(FlagsTypeEntry
*flags
) { m_flags
= flags
; }
651 FlagsTypeEntry
*flags() const { return m_flags
; }
653 bool isExtensible() const { return m_extensible
; }
654 void setExtensible(bool is
) { m_extensible
= is
; }
656 bool isEnumValueRejected(const QString
&name
) { return m_rejected_enums
.contains(name
); }
657 void addEnumValueRejection(const QString
&name
) { m_rejected_enums
<< name
; }
658 QStringList
enumValueRejections() const { return m_rejected_enums
; }
660 void addEnumValueRedirection(const QString
&rejected
, const QString
&usedValue
);
661 QString
enumValueRedirection(const QString
&value
) const;
663 bool forceInteger() const { return m_force_integer
; }
664 void setForceInteger(bool force
) { m_force_integer
= force
; }
667 QString m_package_name
;
671 QString m_lower_bound
;
672 QString m_upper_bound
;
674 QStringList m_rejected_enums
;
675 QList
<EnumValueRedirection
> m_enum_redirections
;
677 FlagsTypeEntry
*m_flags
;
680 bool m_force_integer
;
683 class FlagsTypeEntry
: public TypeEntry
686 FlagsTypeEntry(const QString
&name
) : TypeEntry(name
, FlagsType
), m_enum(0)
690 QString
qualifiedTargetLangName() const;
691 QString
targetLangName() const { return m_java_name
; }
692 QString
jniName() const;
693 virtual bool preferredConversion() const { return false; }
695 QString
originalName() const { return m_original_name
; }
696 void setOriginalName(const QString
&s
) { m_original_name
= s
; }
698 QString
flagsName() const { return m_java_name
; }
699 void setFlagsName(const QString
&name
) { m_java_name
= name
; }
701 bool forceInteger() const { return m_enum
->forceInteger(); }
703 EnumTypeEntry
*originator() const { return m_enum
; }
704 void setOriginator(EnumTypeEntry
*e
) { m_enum
= e
; }
706 QString
javaPackage() const { return m_enum
->javaPackage(); }
709 QString m_original_name
;
711 EnumTypeEntry
*m_enum
;
715 class ComplexTypeEntry
: public TypeEntry
720 DeleteInMainThread
= 0x2,
723 typedef QFlags
<TypeFlag
> TypeFlags
;
725 ComplexTypeEntry(const QString
&name
, Type t
)
726 : TypeEntry(QString(name
).replace("::", "_"), t
),
727 m_qualified_cpp_name(name
),
729 m_polymorphic_base(false),
730 m_generic_class(false),
734 inc
.name
= "QVariant";
735 inc
.type
= Include::IncludePath
;
737 addExtraInclude(inc
);
740 bool isComplex() const { return true; }
742 IncludeList
extraIncludes() const { return m_extra_includes
; }
743 void setExtraIncludes(const IncludeList
&includes
) { m_extra_includes
= includes
; }
744 void addExtraInclude(const Include
&include
)
746 if (!m_includes_used
.value(include
.name
, false)) {
747 m_extra_includes
<< include
;
748 m_includes_used
[include
.name
] = true;
752 ComplexTypeEntry
*copy() const
754 ComplexTypeEntry
*centry
= new ComplexTypeEntry(name(), type());
755 centry
->setInclude(include());
756 centry
->setExtraIncludes(extraIncludes());
757 centry
->setFunctionModifications(functionModifications());
758 centry
->setFieldModifications(fieldModifications());
759 centry
->setQObject(isQObject());
760 centry
->setDefaultSuperclass(defaultSuperclass());
761 centry
->setCodeSnips(codeSnips());
762 centry
->setTargetLangPackage(javaPackage());
767 void setLookupName(const QString
&name
)
769 m_lookup_name
= name
;
772 virtual QString
lookupName() const
774 return m_lookup_name
.isEmpty() ? targetLangName() : m_lookup_name
;
777 QString
jniName() const { return strings_jobject
; }
780 Include
include() const { return m_include
; }
781 void setInclude(const Include
&inc
) { m_include
= inc
; }
783 void setTypeFlags(TypeFlags flags
)
785 m_type_flags
= flags
;
788 TypeFlags
typeFlags() const
793 CodeSnipList
codeSnips() const { return m_code_snips
; }
794 void setCodeSnips(const CodeSnipList
&codeSnips
) { m_code_snips
= codeSnips
; }
795 void addCodeSnip(const CodeSnip
&codeSnip
) { m_code_snips
<< codeSnip
; }
797 FunctionModificationList
functionModifications() const { return m_function_mods
; }
798 void setFunctionModifications(const FunctionModificationList
&functionModifications
) {
799 m_function_mods
= functionModifications
;
801 void addFunctionModification(const FunctionModification
&functionModification
) {
802 m_function_mods
<< functionModification
;
804 FunctionModificationList
functionModifications(const QString
&signature
) const;
806 FieldModification
fieldModification(const QString
&name
) const;
807 void setFieldModifications(const FieldModificationList
&mods
) { m_field_mods
= mods
; }
808 FieldModificationList
fieldModifications() const { return m_field_mods
; }
810 QString
javaPackage() const { return m_package
; }
811 void setTargetLangPackage(const QString
&package
) { m_package
= package
; }
813 bool isQObject() const { return m_qobject
; }
814 void setQObject(bool qobject
) { m_qobject
= qobject
; }
816 QString
defaultSuperclass() const { return m_default_superclass
; }
817 void setDefaultSuperclass(const QString
&sc
) { m_default_superclass
= sc
; }
819 virtual QString
qualifiedCppName() const { return m_qualified_cpp_name
; }
822 void setIsPolymorphicBase(bool on
)
824 m_polymorphic_base
= on
;
826 bool isPolymorphicBase() const { return m_polymorphic_base
; }
828 void setPolymorphicIdValue(const QString
&value
)
830 m_polymorphic_id_value
= value
;
832 QString
polymorphicIdValue() const { return m_polymorphic_id_value
; }
834 void setExpensePolicy(const ExpensePolicy
&policy
) { m_expense_policy
= policy
; }
835 const ExpensePolicy
&expensePolicy() const { return m_expense_policy
; }
837 QString
targetType() const { return m_target_type
; }
838 void setTargetType(const QString
&code
) { m_target_type
= code
; }
840 QString
targetLangName() const { return m_java_name
.isEmpty()
841 ? TypeEntry::targetLangName()
844 void setTargetLangName(const QString
&name
) { m_java_name
= name
; }
846 bool isGenericClass() const { return m_generic_class
; }
847 void setGenericClass(bool isGeneric
) { m_generic_class
= isGeneric
; }
850 IncludeList m_extra_includes
;
852 QHash
<QString
, bool> m_includes_used
;
853 FunctionModificationList m_function_mods
;
854 FieldModificationList m_field_mods
;
855 CodeSnipList m_code_snips
;
857 QString m_default_superclass
;
858 QString m_qualified_cpp_name
;
862 uint m_polymorphic_base
: 1;
863 uint m_generic_class
: 1;
865 QString m_polymorphic_id_value
;
866 QString m_lookup_name
;
867 QString m_target_type
;
868 ExpensePolicy m_expense_policy
;
869 TypeFlags m_type_flags
;
872 class ContainerTypeEntry
: public ComplexTypeEntry
891 ContainerTypeEntry(const QString
&name
, Type type
)
892 : ComplexTypeEntry(name
, ContainerType
)
895 setCodeGeneration(GenerateForSubclass
);
898 Type
type() const { return m_type
; }
899 QString
targetLangName() const;
900 QString
javaPackage() const;
901 QString
qualifiedCppName() const;
908 class NamespaceTypeEntry
: public ComplexTypeEntry
911 NamespaceTypeEntry(const QString
&name
) : ComplexTypeEntry(name
, NamespaceType
) { }
915 class ValueTypeEntry
: public ComplexTypeEntry
918 ValueTypeEntry(const QString
&name
) : ComplexTypeEntry(name
, BasicValueType
) { }
920 bool isValue() const { return true; }
922 virtual bool isNativeIdBased() const { return true; }
925 ValueTypeEntry(const QString
&name
, Type t
) : ComplexTypeEntry(name
, t
) { }
929 class StringTypeEntry
: public ValueTypeEntry
932 StringTypeEntry(const QString
&name
)
933 : ValueTypeEntry(name
, StringType
)
935 setCodeGeneration(GenerateNothing
);
938 QString
jniName() const { return strings_jobject
; }
939 QString
targetLangName() const { return strings_String
; }
940 QString
javaPackage() const { return strings_java_lang
; }
942 virtual bool isNativeIdBased() const { return false; }
945 class CharTypeEntry
: public ValueTypeEntry
948 CharTypeEntry(const QString
&name
) : ValueTypeEntry(name
, CharType
)
950 setCodeGeneration(GenerateNothing
);
953 QString
jniName() const { return strings_jchar
; }
954 QString
targetLangName() const { return strings_char
; }
955 QString
javaPackage() const { return QString(); }
957 virtual bool isNativeIdBased() const { return false; }
960 class JObjectWrapperTypeEntry
: public ValueTypeEntry
963 JObjectWrapperTypeEntry(const QString
&name
) : ValueTypeEntry(name
, JObjectWrapperType
) { }
965 QString
jniName() const { return strings_jobject
; }
966 QString
targetLangName() const { return strings_Object
; }
967 QString
javaPackage() const { return strings_java_lang
; }
969 bool isNativeIdBased() const { return false; }
972 class VariantTypeEntry
: public ValueTypeEntry
975 VariantTypeEntry(const QString
&name
) : ValueTypeEntry(name
, VariantType
) { }
977 QString
jniName() const { return strings_jobject
; }
978 QString
targetLangName() const { return strings_Object
; }
979 QString
javaPackage() const { return strings_java_lang
; }
981 virtual bool isNativeIdBased() const { return false; }
985 class InterfaceTypeEntry
: public ComplexTypeEntry
988 InterfaceTypeEntry(const QString
&name
)
989 : ComplexTypeEntry(name
, InterfaceType
)
993 static QString
interfaceName(const QString
&name
) {
994 return name
+ "Interface";
997 ObjectTypeEntry
*origin() const { return m_origin
; }
998 void setOrigin(ObjectTypeEntry
*origin
) { m_origin
= origin
; }
1000 virtual bool isNativeIdBased() const { return true; }
1001 virtual QString
qualifiedCppName() const {
1002 return ComplexTypeEntry::qualifiedCppName().left(ComplexTypeEntry::qualifiedCppName().length() - interfaceName("").length());
1006 ObjectTypeEntry
*m_origin
;
1010 class ObjectTypeEntry
: public ComplexTypeEntry
1013 ObjectTypeEntry(const QString
&name
)
1014 : ComplexTypeEntry(name
, ObjectType
), m_interface(0)
1018 InterfaceTypeEntry
*designatedInterface() const { return m_interface
; }
1019 void setDesignatedInterface(InterfaceTypeEntry
*entry
) { m_interface
= entry
; }
1021 virtual bool isNativeIdBased() const { return true; }
1024 InterfaceTypeEntry
*m_interface
;
1027 class CustomTypeEntry
: public ComplexTypeEntry
1030 CustomTypeEntry(const QString
&name
) : ComplexTypeEntry(name
, CustomType
) { }
1032 virtual void generateCppJavaToQt(QTextStream
&s
,
1033 const AbstractMetaType
*java_type
,
1034 const QString
&env_name
,
1035 const QString
&qt_name
,
1036 const QString
&java_name
) const = 0;
1038 virtual void generateCppQtToJava(QTextStream
&s
,
1039 const AbstractMetaType
*java_type
,
1040 const QString
&env_name
,
1041 const QString
&qt_name
,
1042 const QString
&java_name
) const = 0;
1045 struct TypeRejection
1048 QString function_name
;
1058 static TypeDatabase
*instance();
1060 QList
<Include
> extraIncludes(const QString
&className
);
1062 inline PrimitiveTypeEntry
*findPrimitiveType(const QString
&name
);
1063 inline ComplexTypeEntry
*findComplexType(const QString
&name
);
1064 inline ObjectTypeEntry
*findObjectType(const QString
&name
);
1065 inline NamespaceTypeEntry
*findNamespaceType(const QString
&name
);
1066 ContainerTypeEntry
*findContainerType(const QString
&name
);
1068 TypeEntry
*findType(const QString
&name
) const {
1069 QList
<TypeEntry
*> entries
= findTypes(name
);
1070 foreach (TypeEntry
*entry
, entries
) {
1072 (!entry
->isPrimitive() || static_cast<PrimitiveTypeEntry
*>(entry
)->preferredTargetLangType())) {
1078 QList
<TypeEntry
*> findTypes(const QString
&name
) const { return m_entries
.value(name
); }
1079 TypeEntryHash
allEntries() { return m_entries
; }
1080 SingleTypeEntryHash
entries() {
1081 TypeEntryHash entries
= allEntries();
1083 SingleTypeEntryHash returned
;
1084 QList
<QString
> keys
= entries
.keys();
1086 foreach(QString key
, keys
) {
1087 returned
[key
] = findType(key
);
1093 PrimitiveTypeEntry
*findTargetLangPrimitiveType(const QString
&java_name
);
1095 void addRejection(const QString
&class_name
, const QString
&function_name
,
1096 const QString
&field_name
, const QString
&enum_name
);
1097 bool isClassRejected(const QString
&class_name
);
1098 bool isFunctionRejected(const QString
&class_name
, const QString
&function_name
);
1099 bool isFieldRejected(const QString
&class_name
, const QString
&field_name
);
1100 bool isEnumRejected(const QString
&class_name
, const QString
&enum_name
);
1102 void addType(TypeEntry
*e
) { m_entries
[e
->qualifiedCppName()].append(e
); }
1104 SingleTypeEntryHash
flagsEntries() const { return m_flags_entries
; }
1105 FlagsTypeEntry
*findFlagsType(const QString
&name
) const;
1106 void addFlagsType(FlagsTypeEntry
*fte
) { m_flags_entries
[fte
->originalName()] = fte
; }
1108 TemplateEntry
*findTemplate(const QString
&name
) { return m_templates
[name
]; }
1109 void addTemplate(TemplateEntry
*t
) { m_templates
[t
->name()] = t
; }
1111 void setSuppressWarnings(bool on
) { m_suppressWarnings
= on
; }
1112 void addSuppressedWarning(const QString
&s
)
1114 m_suppressedWarnings
.append(s
);
1117 bool isSuppressedWarning(const QString
&s
)
1119 if (!m_suppressWarnings
)
1122 foreach (const QString
&_warning
, m_suppressedWarnings
) {
1123 QString
warning(QString(_warning
).replace("\\*", "&place_holder_for_asterisk;"));
1125 QStringList segs
= warning
.split("*", QString::SkipEmptyParts
);
1126 if (segs
.size() == 0)
1130 int pos
= s
.indexOf(QString(segs
.at(i
++)).replace("&place_holder_for_asterisk;", "*"));
1131 //qDebug() << "s == " << s << ", warning == " << segs;
1133 if (i
== segs
.size())
1135 pos
= s
.indexOf(QString(segs
.at(i
++)).replace("&place_holder_for_asterisk;", "*"), pos
);
1142 void setRebuildClasses(const QStringList
&cls
) { m_rebuild_classes
= cls
; }
1144 static QString
globalNamespaceClassName(const TypeEntry
*te
);
1145 QString
filename() const { return "typesystem.txt"; }
1147 bool parseFile(const QString
&filename
, bool generate
= true);
1150 bool m_suppressWarnings
;
1151 TypeEntryHash m_entries
;
1152 SingleTypeEntryHash m_flags_entries
;
1153 TemplateEntryHash m_templates
;
1154 QStringList m_suppressedWarnings
;
1156 QList
<TypeRejection
> m_rejections
;
1157 QStringList m_rebuild_classes
;
1160 inline PrimitiveTypeEntry
*TypeDatabase::findPrimitiveType(const QString
&name
)
1162 QList
<TypeEntry
*> entries
= findTypes(name
);
1164 foreach (TypeEntry
*entry
, entries
) {
1165 if (entry
!= 0 && entry
->isPrimitive() && static_cast<PrimitiveTypeEntry
*>(entry
)->preferredTargetLangType())
1166 return static_cast<PrimitiveTypeEntry
*>(entry
);
1172 inline ComplexTypeEntry
*TypeDatabase::findComplexType(const QString
&name
)
1174 TypeEntry
*entry
= findType(name
);
1175 if (entry
!= 0 && entry
->isComplex())
1176 return static_cast<ComplexTypeEntry
*>(entry
);
1181 inline ObjectTypeEntry
*TypeDatabase::findObjectType(const QString
&name
)
1183 TypeEntry
*entry
= findType(name
);
1184 if (entry
!= 0 && entry
->isObject())
1185 return static_cast<ObjectTypeEntry
*>(entry
);
1190 inline NamespaceTypeEntry
*TypeDatabase::findNamespaceType(const QString
&name
)
1192 TypeEntry
*entry
= findType(name
);
1193 if (entry
!= 0 && entry
->isNamespace())
1194 return static_cast<NamespaceTypeEntry
*>(entry
);
1199 QString
fixCppTypeName(const QString
&name
);
1201 #endif // TYPESYSTEM_H