Mercurial > projects > qtd
comparison generator/dgenerator.cpp @ 372:a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Thu, 08 Jul 2010 17:19:05 +0300 |
parents | 185df9220ea7 |
children | 7341c47790d4 |
comparison
equal
deleted
inserted
replaced
370:7fd4b69378bf | 372:a032df77b6ab |
---|---|
490 } | 490 } |
491 | 491 |
492 static QString function_call_for_ownership(TypeSystem::Ownership owner) | 492 static QString function_call_for_ownership(TypeSystem::Ownership owner) |
493 { | 493 { |
494 if (owner == TypeSystem::CppOwnership) { | 494 if (owner == TypeSystem::CppOwnership) { |
495 return "__setFlags(QtdObjectFlags.nativeOwnership, true)"; | 495 return "qtdSetOwnership(QtdObjectOwnership.native)"; |
496 } else /* qtd 2 if (owner == TypeSystem::TargetLangOwnership) */ { | 496 } else /* qtd 2 if (owner == TypeSystem::TargetLangOwnership) */ { |
497 return "__setFlags(QtdObjectFlags.nativeOwnership, false)"; | 497 return "qtdSetOwnership(QtdObjectOwnership.d)"; |
498 }/* else if (owner == TypeSystem::DefaultOwnership) { | 498 }/* else if (owner == TypeSystem::DefaultOwnership) { |
499 return "__no_real_delete = false"; | 499 return "__no_real_delete = false"; |
500 | 500 |
501 } else { | 501 } else { |
502 Q_ASSERT(false); | 502 Q_ASSERT(false); |
786 } | 786 } |
787 | 787 |
788 bool arg_written = false; | 788 bool arg_written = false; |
789 | 789 |
790 if (!d_function->isConstructor() && !d_function->isStatic()) { | 790 if (!d_function->isConstructor() && !d_function->isStatic()) { |
791 s << "(cast(" << d_function->ownerClass()->name() << ")this).__nativeId"; | 791 s << "qtdNativeId"; |
792 arg_written = true; | 792 arg_written = true; |
793 } | 793 } |
794 | 794 |
795 if (d_function->isConstructor() && | 795 if (d_function->isConstructor() && |
796 ( d_function->ownerClass()->isPolymorphic() | 796 ( d_function->ownerClass()->isPolymorphic() |
824 modified_type = modified_type.replace('$', '.'); | 824 modified_type = modified_type.replace('$', '.'); |
825 | 825 |
826 QString arg_name = arg->argumentName(); | 826 QString arg_name = arg->argumentName(); |
827 | 827 |
828 if (type->isVariant()) | 828 if (type->isVariant()) |
829 s << arg_name << " is null ? null : " << arg_name << ".__nativeId"; | 829 s << arg_name << " is null ? null : " << arg_name << ".qtdNativeId"; |
830 else if (te->designatedInterface()) | 830 else if (te->designatedInterface()) |
831 s << arg_name << " is null ? null : " << arg_name << ".__ptr_" << te->designatedInterface()->name(); | 831 s << arg_name << " is null ? null : " << arg_name << ".__ptr_" << te->designatedInterface()->name(); |
832 else if (modified_type == "string" /* && type->fullName() == "char" */) { | 832 else if (modified_type == "string" /* && type->fullName() == "char" */) { |
833 s << "toStringz(" << arg_name << ")"; | 833 s << "toStringz(" << arg_name << ")"; |
834 } else if (type->isArray()) { | 834 } else if (type->isArray()) { |
854 if (!force_abstract) { | 854 if (!force_abstract) { |
855 s << arg_name << " is null ? null : "; | 855 s << arg_name << " is null ? null : "; |
856 } // else if (value type is abstract) then we will get a null pointer exception, which is all right | 856 } // else if (value type is abstract) then we will get a null pointer exception, which is all right |
857 | 857 |
858 if(dVersion == 2 && type->isConstant()) | 858 if(dVersion == 2 && type->isConstant()) |
859 s << "(cast(" << type->name() << ")" << arg_name << ").__nativeId"; | 859 s << "(cast(" << type->name() << ")" << arg_name << ").qtdNativeId"; |
860 else | 860 else |
861 s << arg_name << ".__nativeId"; | 861 s << arg_name << ".qtdNativeId"; |
862 } | 862 } |
863 } | 863 } |
864 } | 864 } |
865 | 865 |
866 if (useJumpTable) { | 866 if (useJumpTable) { |
929 | 929 |
930 if (return_type->isVariant()) | 930 if (return_type->isVariant()) |
931 s << "new QVariant(ret);" << endl; | 931 s << "new QVariant(ret);" << endl; |
932 | 932 |
933 if (return_type->isNativePointer() && return_type->typeEntry()->isValue()) | 933 if (return_type->isNativePointer() && return_type->typeEntry()->isValue()) |
934 s << "new " << return_type->name() << "(ret, QtdObjectFlags.nativeOwnership);" << endl; | 934 s << "new " << return_type->name() << "(ret, QtdObjectInitFlags.nativeOwnership);" << endl; |
935 | 935 |
936 if (return_type->isObject()) { | 936 if (return_type->isObject()) { |
937 s << "qtd_" << return_type->name() << "_from_ptr(ret);" << endl << endl; | 937 s << "qtd_" << return_type->name() << "_from_ptr(ret);" << endl << endl; |
938 } | 938 } |
939 | 939 |
1713 if (!d_class->hasConstructors()) | 1713 if (!d_class->hasConstructors()) |
1714 return; | 1714 return; |
1715 | 1715 |
1716 if (d_class->isDestructorBase()) | 1716 if (d_class->isDestructorBase()) |
1717 { | 1717 { |
1718 s << INDENT << "protected override void __deleteNative() {" << endl; | 1718 s << INDENT << "protected override void qtdDeleteNative() {" << endl; |
1719 { | 1719 { |
1720 s << INDENT << "qtd_" << d_class->name() << "_delete(__nativeId);" << endl; | 1720 s << INDENT << " qtd_" << d_class->name() << "_delete(qtdNativeId);" << endl; |
1721 } | 1721 } |
1722 s << INDENT << "}" << endl << endl; | 1722 s << INDENT << "}" << endl << endl; |
1723 | 1723 |
1724 s << INDENT << "static void __deleteNativeObject(void* ptr) {" << endl | 1724 s << INDENT << "static void __deleteNativeObject(void* ptr) {" << endl |
1725 << INDENT << " qtd_" << d_class->name() << "_delete(ptr);" << endl | 1725 << INDENT << " qtd_" << d_class->name() << "_delete(ptr);" << endl |
1729 << INDENT << " qtd_" << d_class->name() << "_destroy(nativeId);" << endl | 1729 << INDENT << " qtd_" << d_class->name() << "_destroy(nativeId);" << endl |
1730 << INDENT << "}" << endl << endl; | 1730 << INDENT << "}" << endl << endl; |
1731 } | 1731 } |
1732 } | 1732 } |
1733 | 1733 |
1734 void DGenerator::writeFlagsSetter(QTextStream &s, const AbstractMetaClass *d_class) | 1734 void DGenerator::writeOwnershipSetter(QTextStream &s, const AbstractMetaClass *d_class) |
1735 { | 1735 { |
1736 if (d_class->isInterface()) | 1736 if (d_class->isInterface()) |
1737 s << INDENT << "void __setFlags(QtdObjectFlags flags, bool val);"; | 1737 s << INDENT << "void qtdSetOwnership(QtdObjectOwnership own) const;"; |
1738 else if (!d_class->isNamespace()) // COMPILER BUG: | 1738 else if (!d_class->isNamespace()) // COMPILER BUG: |
1739 s << INDENT << "void __setFlags(QtdObjectFlags flags, bool val) { super.__setFlags(flags, val); }"; | 1739 s << INDENT << "void qtdSetOwnership(QtdObjectOwnership own) const { super.qtdSetOwnership(own); }"; |
1740 } | 1740 } |
1741 | 1741 |
1742 void DGenerator::writeSignalHandlers(QTextStream &s, const AbstractMetaClass *d_class) | 1742 void DGenerator::writeSignalHandlers(QTextStream &s, const AbstractMetaClass *d_class) |
1743 { | 1743 { |
1744 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class); | 1744 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class); |
1794 QString type_name = type->name(); | 1794 QString type_name = type->name(); |
1795 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); | 1795 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); |
1796 if(ctype->isAbstract()) | 1796 if(ctype->isAbstract()) |
1797 type_name = type_name + "_ConcreteWrapper"; | 1797 type_name = type_name + "_ConcreteWrapper"; |
1798 s << INDENT << "scope " << arg_name << " = new " << type_name | 1798 s << INDENT << "scope " << arg_name << " = new " << type_name |
1799 << "(cast(void*)(" << arg_ptr << "), QtdObjectFlags.nativeOwnership);" << endl; | 1799 << "(cast(void*)(" << arg_ptr << "), QtdObjectInitFlags.onStack);" << endl; |
1800 } | 1800 } |
1801 s << endl; | 1801 s << endl; |
1802 } | 1802 } |
1803 // s << INDENT << "Stdout(\"" << d_class->name() << "\", \"" << signal->name() << "\").newline;" << endl; | 1803 // s << INDENT << "Stdout(\"" << d_class->name() << "\", \"" << signal->name() << "\").newline;" << endl; |
1804 s << INDENT << "//d_object." << signal->name() << "_emit("; | 1804 s << INDENT << "//d_object." << signal->name() << "_emit("; |
1949 } | 1949 } |
1950 | 1950 |
1951 if (!m_isRecursive) { | 1951 if (!m_isRecursive) { |
1952 s << "public import qt.QGlobal;" << endl | 1952 s << "public import qt.QGlobal;" << endl |
1953 << "public import qt.core.Qt;" << endl | 1953 << "public import qt.core.Qt;" << endl |
1954 << "private import qtd.QtdObject;" << endl | 1954 << "import qtd.QtdObject;" << endl |
1955 << "private import qt.core.QString;" << endl | 1955 << "import qt.core.QString;" << endl |
1956 << "private import qtd.Array;" << endl | 1956 << "import qtd.Array;" << endl |
1957 << "private import qt.core.QList;" << endl; | 1957 << "import qt.core.QList;" << endl; |
1958 if (d_class->isQObject()) { | 1958 if (d_class->isQObject()) { |
1959 s << "public import qtd.Signal;" << endl | 1959 // TODO: just move those to a separate module publicly imported by QObject |
1960 << "public import qtd.MOC;" << endl | 1960 // or to QObject itself |
1961 << "public import qt.core.QMetaObject;" << endl | 1961 s << "public import qtd.MOC : Q_OBJECT;" << endl |
1962 << "import qtd.meta.Runtime;"; | 1962 |
1963 << "import qtd.Signal;" << endl | |
1964 << "import qt.core.QMetaObject;" << endl | |
1965 << "import qtd.meta.Runtime;" << endl; | |
1963 | 1966 |
1964 if (d_class->name() != "QObject") | 1967 if (d_class->name() != "QObject") |
1965 s << "public import qt.core.QObject;" << endl; | 1968 s << "import qt.core.QObject;" << endl; |
1966 } | 1969 } |
1967 | 1970 |
1968 // qtd2 hack! | 1971 // qtd2 hack! |
1969 if (d_class->name() == "QCoreApplication") | 1972 if (d_class->name() == "QCoreApplication") |
1970 s << "private import qt.core.ArrayOps;" << endl; | 1973 s << "private import qt.core.ArrayOps;" << endl; |
2312 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) { | 2315 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) { |
2313 s << endl | 2316 s << endl |
2314 << INDENT << "public " | 2317 << INDENT << "public " |
2315 << "this"; | 2318 << "this"; |
2316 | 2319 |
2317 | 2320 s << "(void* nativeId, QtdObjectInitFlags initFlags = QtdObjectInitFlags.none) {" << endl; |
2318 Indentation indent(INDENT); | 2321 |
2319 | |
2320 s << "(void* native_id, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl | |
2321 << INDENT << "super(native_id, flags);" << endl; | |
2322 | |
2323 if (d_class->name() == "QObject") | |
2324 { | 2322 { |
2325 // To prevent GC from collecting the object, add it to the statically rooted linked list | 2323 Indentation indent(INDENT); |
2326 s << INDENT << " __next = __root;" << endl | 2324 |
2327 << INDENT << " __root = this;" << endl | 2325 if (d_class->name() == "QObject") { |
2328 << INDENT << " if (__next) {" << endl | 2326 s << INDENT << "//assert (!(initFlags & QtdObjectInitFlags.onStack));" << endl |
2329 << INDENT << " __next.__prev = this;" << endl | 2327 << INDENT << "qtdPin();" << endl |
2330 << INDENT << " }" << endl << endl; | 2328 << INDENT << "_flags.isQObject = true;" << endl; |
2331 } | 2329 } |
2332 | 2330 |
2333 /* | 2331 // only QObjects are handled polymorphically for now |
2334 if (cpp_shared) { | 2332 if (d_class->name() == "QObject" /* d_class->polymorphicBase() == d_class */) |
2335 if (d_class->generateShellClass() && !d_class->isInterface()) | 2333 s << INDENT << "_flags.polymorphic = true;" << endl; |
2336 s << INDENT << "if (!static_inited)" << endl | 2334 |
2337 << INDENT << " static_init_" << d_class->name() << "();" << endl << endl; | 2335 s << INDENT << "super(nativeId, initFlags);" << endl; |
2338 } | 2336 |
2339 */ | 2337 // pointers to native interface objects for classes that implement interfaces |
2340 | 2338 // initializing |
2341 | 2339 interfaces = d_class->interfaces(); |
2342 // pointers to native interface objects for classes that implement interfaces | 2340 if (!interfaces.isEmpty()) { |
2343 // initializing | 2341 for (int i=0; i<interfaces.size(); ++i) { |
2344 interfaces = d_class->interfaces(); | 2342 AbstractMetaClass *iface = interfaces.at(i); |
2345 if (!interfaces.isEmpty()) { | 2343 |
2346 for (int i=0; i<interfaces.size(); ++i) { | 2344 s << INDENT << " __m_ptr_" << iface->name() << " = qtd_" << d_class->name() << "_cast_to_" << iface->qualifiedCppName() |
2347 AbstractMetaClass *iface = interfaces.at(i); | 2345 << "(nativeId);" << endl; |
2348 | 2346 } |
2349 s << INDENT << " __m_ptr_" << iface->name() << " = qtd_" << d_class->name() << "_cast_to_" << iface->qualifiedCppName() | 2347 } |
2350 << "(__nativeId);" << endl; | 2348 } |
2351 } | |
2352 } | |
2353 | |
2354 | 2349 |
2355 s << INDENT << "}" << endl << endl; | 2350 s << INDENT << "}" << endl << endl; |
2356 | 2351 |
2357 // pointers to native interface objects for classes that implement interfaces | 2352 // pointers to native interface objects for classes that implement interfaces |
2358 // initializing | 2353 // initializing |
2395 } | 2390 } |
2396 */ | 2391 */ |
2397 | 2392 |
2398 /* qtd writeJavaLangObjectOverrideFunctions(s, d_class); | 2393 /* qtd writeJavaLangObjectOverrideFunctions(s, d_class); |
2399 */ | 2394 */ |
2400 writeFlagsSetter(s, d_class); | 2395 writeOwnershipSetter(s, d_class); |
2401 s << "// Injected code in class" << endl; | 2396 s << "// Injected code in class" << endl; |
2402 writeExtraFunctions(s, d_class); | 2397 writeExtraFunctions(s, d_class); |
2403 // qtd2 writeToStringFunction(s, d_class); | 2398 // qtd2 writeToStringFunction(s, d_class); |
2404 /* qtd | 2399 /* qtd |
2405 if (d_class->hasCloneOperator()) { | 2400 if (d_class->hasCloneOperator()) { |
2436 | 2431 |
2437 s << INDENT << "public class " << d_class->name() << "_ConcreteWrapper : " << d_class->name() << " {" << endl; | 2432 s << INDENT << "public class " << d_class->name() << "_ConcreteWrapper : " << d_class->name() << " {" << endl; |
2438 | 2433 |
2439 { | 2434 { |
2440 Indentation indent(INDENT); | 2435 Indentation indent(INDENT); |
2441 QString hasShellFlag = d_class->generateShellClass() ? " | QtdObjectFlags.hasShell" : ""; | 2436 |
2442 s << INDENT << "public this(void* native_id, QtdObjectFlags flags = QtdObjectFlags.nativeOwnership) {" << endl | 2437 s << INDENT << "public this(void* native_id, QtdObjectInitFlags initFlags = QtdObjectInitFlags.nativeOwnership) {" << endl |
2443 << INDENT << " super(native_id, flags);" << endl << endl; | 2438 << INDENT << " super(native_id, initFlags);" << endl << endl; |
2444 | 2439 |
2445 s << INDENT << "}" << endl << endl; | 2440 s << INDENT << "}" << endl << endl; |
2446 | 2441 |
2447 uint exclude_attributes = AbstractMetaAttributes::Native | AbstractMetaAttributes::Abstract; | 2442 uint exclude_attributes = AbstractMetaAttributes::Native | AbstractMetaAttributes::Abstract; |
2448 uint include_attributes = 0; | 2443 uint include_attributes = 0; |
2675 s << INDENT << "void* d_obj = __" << ctype->targetLangName() << "_entity(ret);" << endl | 2670 s << INDENT << "void* d_obj = __" << ctype->targetLangName() << "_entity(ret);" << endl |
2676 << INDENT << "if (d_obj !is null) {" << endl | 2671 << INDENT << "if (d_obj !is null) {" << endl |
2677 << INDENT << " auto d_obj_ref = cast (Object) d_obj;" << endl | 2672 << INDENT << " auto d_obj_ref = cast (Object) d_obj;" << endl |
2678 << INDENT << " return cast(" << return_type_name << ") d_obj_ref;" << endl | 2673 << INDENT << " return cast(" << return_type_name << ") d_obj_ref;" << endl |
2679 << INDENT << "} else {" << endl | 2674 << INDENT << "} else {" << endl |
2680 << INDENT << " auto return_value = new " << type_name << "(ret, QtdObjectFlags.nativeOwnership);" << endl | 2675 << INDENT << " auto return_value = new " << type_name << "(ret, QtdObjectInitFlags.nativeOwnership);" << endl |
2681 << INDENT << " return return_value;" << endl | 2676 << INDENT << " return return_value;" << endl |
2682 << INDENT << "}" << endl; | 2677 << INDENT << "}" << endl; |
2683 } else { | 2678 } else { |
2684 s << INDENT << "auto return_value = new " << type_name << "(ret, QtdObjectFlags.nativeOwnership);" << endl | 2679 s << INDENT << "auto return_value = new " << type_name << "(ret, QtdObjectInitFlags.nativeOwnership);" << endl |
2685 << INDENT << "return return_value;" << endl; | 2680 << INDENT << "return return_value;" << endl; |
2686 } | 2681 } |
2687 s << "}" << endl << endl; | 2682 s << "}" << endl << endl; |
2688 } | 2683 } |
2689 | 2684 |
2690 void DGenerator::writeQObjectFreeFunctions(QTextStream &s, const AbstractMetaClass *d_class) | 2685 void DGenerator::writeQObjectFreeFunctions(QTextStream &s, const AbstractMetaClass *d_class) |
2691 { | 2686 { |
2692 s << "extern(C) QMetaObjectNative* qtd_" << d_class->name() << "_staticMetaObject();" << endl << endl | 2687 s << "extern(C) QMetaObjectNative* qtd_" << d_class->name() << "_staticMetaObject();" << endl << endl |
2693 << "extern(C) void qtd_" << d_class->name() << "_createEntity(void* nativeId, void* dId);" << endl << endl | 2688 << "extern(C) void qtd_" << d_class->name() << "_createEntity(void* nativeId, void* dId);" << endl << endl |
2694 << "extern(C) int qtd_" << d_class->name() << "_qt_metacall(void *nativeId, QMetaObject.Call _c, int _id, void **_a);" << endl; | 2689 << "extern(C) int qtd_" << d_class->name() << "_qt_metacall(void *nativeId, MetaCall _c, int _id, void **_a);" << endl; |
2695 | 2690 |
2696 QString prefix = cpp_shared ? "qtd_export_" : "qtd_"; | 2691 QString prefix = cpp_shared ? "qtd_export_" : "qtd_"; |
2697 | 2692 |
2698 if (d_class->name() == "QObject") { | 2693 if (d_class->name() == "QObject") { |
2699 s << "extern(C) int " << prefix << "QObject_qt_metacall_dispatch(void *d_entity, QMetaObject.Call _c, int _id, void **_a) {" << endl | 2694 s << "extern(C) int " << prefix << "QObject_qt_metacall_dispatch(void *d_entity, MetaCall _c, int _id, void **_a) {" << endl |
2700 << " auto d_object = cast(QObject) d_entity;" << endl | 2695 << " auto d_object = cast(QObject) d_entity;" << endl |
2701 << " return d_object.qt_metacall(_c, _id, _a);" << endl | 2696 << " return d_object.qt_metacall(_c, _id, _a);" << endl |
2702 << "};" << endl << endl; | 2697 << "};" << endl << endl; |
2703 | 2698 |
2704 s << "extern(C) void* " << prefix << "QObject_metaObject_dispatch(void *d_entity) {" << endl | 2699 s << "extern(C) void* " << prefix << "QObject_metaObject_dispatch(void *d_entity) {" << endl |
2745 if(function->isSlot()) | 2740 if(function->isSlot()) |
2746 slot_funcs += function; | 2741 slot_funcs += function; |
2747 } | 2742 } |
2748 writeMetaMethodSignatures(s, "__slotSignatures", slot_funcs); | 2743 writeMetaMethodSignatures(s, "__slotSignatures", slot_funcs); |
2749 | 2744 |
2750 if (d_class->isAbstract()) | 2745 QString concrete_name = d_class->isAbstract() ? d_class->name() + "_ConcreteWrapper" : d_class->name(); |
2751 s << "alias " << d_class->name() << "_ConcreteWrapper ConcreteType;" << endl; | |
2752 | 2746 |
2753 if (!d_class->isFinal()) { | 2747 if (!d_class->isFinal()) { |
2754 s << " int qt_metacall(QMetaObject.Call _c, int _id, void **_a) {" << endl | 2748 s << " int qt_metacall(MetaCall _c, int _id, void **_a) {" << endl |
2755 << " return qtd_" << d_class->name() << "_qt_metacall(__nativeId, _c, _id, _a);" << endl | 2749 << " return qtd_" << d_class->name() << "_qt_metacall(qtdNativeId, _c, _id, _a);" << endl |
2756 << " }" << endl << endl; | 2750 << " }" << endl << endl; |
2757 } | 2751 } |
2758 | 2752 |
2759 s << " @property QMetaObject metaObject() {" << endl | 2753 s << " @property QMetaObject metaObject() {" << endl |
2760 << " return staticMetaObject;" << endl | 2754 << " return staticMetaObject;" << endl |
2763 << " @property static QMetaObject staticMetaObject() {" << endl | 2757 << " @property static QMetaObject staticMetaObject() {" << endl |
2764 << " return meta!(" << d_class->name() << ");" << endl | 2758 << " return meta!(" << d_class->name() << ");" << endl |
2765 << " }" << endl << endl | 2759 << " }" << endl << endl |
2766 | 2760 |
2767 << " static " << d_class->name() << " __getObject(void* nativeId) {" << endl | 2761 << " static " << d_class->name() << " __getObject(void* nativeId) {" << endl |
2768 << " return static_cast!(" << d_class->name() << ")(staticMetaObject.getObject(nativeId));" << endl | 2762 << " return static_cast!(" << d_class->name() << ")(staticMetaObject.getWrapper(nativeId));" << endl |
2769 << " }" << endl << endl | 2763 << " }" << endl << endl |
2770 | 2764 |
2771 << " static void __createEntity(void* nativeId, void* dId) {" << endl | 2765 << " static void __createEntity(void* nativeId, void* dId) {" << endl |
2772 << " return qtd_" << d_class->name() << "_createEntity(nativeId, dId);" << endl | 2766 << " return qtd_" << d_class->name() << "_createEntity(nativeId, dId);" << endl |
2773 << " }" << endl << endl | 2767 << " }" << endl << endl |
2774 | 2768 |
2775 << " static void* qtd_nativeStaticMetaObject() {" << endl | 2769 << " static void* qtdNativeStaticMetaObject() {" << endl |
2776 << " return qtd_" << d_class->name() << "_staticMetaObject();" << endl | 2770 << " return qtd_" << d_class->name() << "_staticMetaObject();" << endl |
2777 << " }" << endl | 2771 << " }" << endl |
2772 | |
2773 << " static QtdObject qtdCreateWrapper(void* nativeId, QtdObjectInitFlags initFlags) {" << endl | |
2774 << " auto obj = new " << concrete_name << "(nativeId, initFlags);" << endl | |
2775 << " " << d_class->name() << ".__createEntity(nativeId, cast(void*)obj);" << endl | |
2776 << " return obj;" << endl | |
2777 << " }" << endl << endl | |
2778 | 2778 |
2779 << " static void _populateMetaInfo(QMetaObject mo) {" << endl | 2779 << " static void _populateMetaInfo(QMetaObject mo) {" << endl |
2780 << " int index;" << endl << endl; | 2780 << " int index;" << endl << endl; |
2781 | 2781 |
2782 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class, false); | 2782 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class, false); |
2824 staticId++; | 2824 staticId++; |
2825 } while (hasDefault); | 2825 } while (hasDefault); |
2826 } | 2826 } |
2827 | 2827 |
2828 s << " }" << endl << endl; | 2828 s << " }" << endl << endl; |
2829 | |
2830 s << INDENT << "mixin Q_OBJECT_BIND;" << endl << endl; | |
2831 } | 2829 } |
2832 | 2830 |
2833 void DGenerator::marshalFromCppToD(QTextStream &s, const ComplexTypeEntry* ctype) | 2831 void DGenerator::marshalFromCppToD(QTextStream &s, const ComplexTypeEntry* ctype) |
2834 { | 2832 { |
2835 if(ctype->isQObject()) { | 2833 if(ctype->isQObject()) { |
2994 << arg_name << "[0.." << arg_name << "_size]);"; | 2992 << arg_name << "[0.." << arg_name << "_size]);"; |
2995 else if (type->typeEntry()->isValue() && type->isNativePointer() && type->typeEntry()->name() == "QString") { | 2993 else if (type->typeEntry()->isValue() && type->isNativePointer() && type->typeEntry()->name() == "QString") { |
2996 s << INDENT << "auto " << arg_name << "_d_qstr = QStringUtil(" << arg_name << ", true);" << endl | 2994 s << INDENT << "auto " << arg_name << "_d_qstr = QStringUtil(" << arg_name << ", true);" << endl |
2997 << INDENT << "string " << arg_name << "_d_ref = " << arg_name << "_d_qstr.toNativeString();"; | 2995 << INDENT << "string " << arg_name << "_d_ref = " << arg_name << "_d_qstr.toNativeString();"; |
2998 } else if(type->isVariant()) | 2996 } else if(type->isVariant()) |
2999 s << INDENT << "scope " << arg_name << "_d_ref = new QVariant(" << arg_name << ", QtdObjectFlags.nativeOwnership);"; | 2997 s << INDENT << "scope " << arg_name << "_d_ref = new QVariant(" << arg_name << ", QtdObjectInitFlags.onStack);"; |
3000 else if (type->typeEntry()->isStructInD()) | 2998 else if (type->typeEntry()->isStructInD()) |
3001 continue; | 2999 continue; |
3002 else if (!type->hasNativeId() && !(type->typeEntry()->isValue() && type->isNativePointer())) | 3000 else if (!type->hasNativeId() && !(type->typeEntry()->isValue() && type->isNativePointer())) |
3003 continue; | 3001 continue; |
3004 else if(type->isObject() | 3002 else if(type->isObject() |
3006 || type->isValue() || type->isVariant()) { | 3004 || type->isValue() || type->isVariant()) { |
3007 QString type_name = type->typeEntry()->name(); | 3005 QString type_name = type->typeEntry()->name(); |
3008 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); | 3006 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); |
3009 if(ctype->isAbstract()) | 3007 if(ctype->isAbstract()) |
3010 type_name = type_name + "_ConcreteWrapper"; | 3008 type_name = type_name + "_ConcreteWrapper"; |
3011 s << INDENT << "scope " << arg_name << "_d_ref = new " << type_name << "(" << arg_name << ", QtdObjectFlags.nativeOwnership);"; | 3009 s << INDENT << "scope " << arg_name << "_d_ref = new " << type_name << "(" << arg_name << ", QtdObjectInitFlags.onStack);"; |
3012 } | 3010 } |
3013 else if (type->isQObject()) { | 3011 else if (type->isQObject()) { |
3014 QString type_name = type->name(); | 3012 QString type_name = type->name(); |
3015 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); | 3013 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); |
3016 if(ctype->isAbstract()) | 3014 if(ctype->isAbstract()) |
3017 type_name = type_name + "_ConcreteWrapper"; | 3015 type_name = type_name + "_ConcreteWrapper"; |
3018 | 3016 |
3019 s << INDENT << "scope " << arg_name << "_d_ref = new " << type_name << "(" << arg_name << ", QtdObjectFlags.nativeOwnership);" << endl; | 3017 s << INDENT << "scope " << arg_name << "_d_ref = new " << type_name << "(" << arg_name << ", QtdObjectInitFlags.onStack);" << endl; |
3020 } | 3018 } |
3021 s << endl; | 3019 s << endl; |
3022 } | 3020 } |
3023 } | 3021 } |
3024 | 3022 |
3096 if(has_return_type) { | 3094 if(has_return_type) { |
3097 AbstractMetaType *f_type = d_function->type(); | 3095 AbstractMetaType *f_type = d_function->type(); |
3098 if(f_type) { | 3096 if(f_type) { |
3099 if(f_type->isObject() || f_type->isQObject() || f_type->isVariant() || | 3097 if(f_type->isObject() || f_type->isQObject() || f_type->isVariant() || |
3100 (f_type->isValue() && !f_type->typeEntry()->isStructInD())) { | 3098 (f_type->isValue() && !f_type->typeEntry()->isStructInD())) { |
3101 QString native_id = "__nativeId"; | 3099 QString native_id = "qtdNativeId"; |
3102 if (f_type->typeEntry()->designatedInterface()) | 3100 if (f_type->typeEntry()->designatedInterface()) |
3103 native_id = "__ptr_" + f_type->typeEntry()->designatedInterface()->name(); | 3101 native_id = "__ptr_" + f_type->typeEntry()->designatedInterface()->name(); |
3104 s << INDENT << "return ret_value is null? null : ret_value." << native_id << ";" << endl; | 3102 s << INDENT << "return ret_value is null? null : ret_value." << native_id << ";" << endl; |
3105 } else if (f_type->isTargetLangString()) | 3103 } else if (f_type->isTargetLangString()) |
3106 s << INDENT << "*ret_str = _d_str;" << endl; | 3104 s << INDENT << "*ret_str = _d_str;" << endl; |
3373 { | 3371 { |
3374 // Write constructor | 3372 // Write constructor |
3375 s << " {" << endl; | 3373 s << " {" << endl; |
3376 { | 3374 { |
3377 Indentation indent(INDENT); | 3375 Indentation indent(INDENT); |
3378 bool shellClass = d_function->ownerClass()->generateShellClass(); | |
3379 | |
3380 writeJavaCallThroughContents(s, d_function); | 3376 writeJavaCallThroughContents(s, d_function); |
3381 | 3377 |
3382 // Write out expense checks if present... | 3378 // Write out expense checks if present... |
3383 const AbstractMetaClass *d_class = d_function->implementingClass(); | 3379 const AbstractMetaClass *d_class = d_function->implementingClass(); |
3384 const ComplexTypeEntry *te = d_class->typeEntry(); | 3380 const ComplexTypeEntry *te = d_class->typeEntry(); |
3393 if (snip.language == TypeSystem::Constructors) { | 3389 if (snip.language == TypeSystem::Constructors) { |
3394 snip.formattedCode(s, INDENT); | 3390 snip.formattedCode(s, INDENT); |
3395 } | 3391 } |
3396 } | 3392 } |
3397 | 3393 |
3398 s << INDENT << "this(ret);" << endl; | 3394 s << INDENT << "this(ret, QtdObjectInitFlags.createdByD);" << endl; |
3399 } | 3395 } |
3400 s << INDENT << "}" << endl << endl; | 3396 s << INDENT << "}" << endl << endl; |
3401 | 3397 |
3402 /* qtd // Write native constructor | 3398 /* qtd // Write native constructor |
3403 if (d_function->jumpTableId() == -1) | 3399 if (d_function->jumpTableId() == -1) |
3464 << " }" << endl; | 3460 << " }" << endl; |
3465 } else { | 3461 } else { |
3466 s << endl | 3462 s << endl |
3467 << " @Override" << endl | 3463 << " @Override" << endl |
3468 << " public String toString() {" << endl | 3464 << " public String toString() {" << endl |
3469 << " if (__nativeId == 0)" << endl | 3465 << " if (qtdNativeId == 0)" << endl |
3470 << " throw new QNoNativeResourcesException(\"Function call on incomplete object of type: \" +getClass().getName());" << endl | 3466 << " throw new QNoNativeResourcesException(\"Function call on incomplete object of type: \" +getClass().getName());" << endl |
3471 << " return __qt_toString(nativeId());" << endl | 3467 << " return __qt_toString(nativeId());" << endl |
3472 << " }" << endl | 3468 << " }" << endl |
3473 << " native String __qt_toString(long __this_nativeId);" << endl; | 3469 << " native String __qt_toString(long __this_nativeId);" << endl; |
3474 } | 3470 } |