comparison generator/dgenerator.cpp @ 310:5bcfe9e7db7f lifetime

Committing local changes
author maxter <spambox@d-coding.com>
date Wed, 23 Dec 2009 16:10:46 +0200
parents a7b313b8b149
children 80b52f5e97b6
comparison
equal deleted inserted replaced
263:a7b313b8b149 310:5bcfe9e7db7f
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special 21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special
22 * exception, Nokia gives you certain additional rights. These rights 22 * exception, Nokia gives you certain additional rights. These rights
23 * are described in the Nokia Qt GPL Exception version 1.2, included in 23 * are described in the Nokia Qt GPL Exception version 1.2, included in
24 * the file GPL_EXCEPTION.txt in this package. 24 * the file GPL_EXCEPTION.txt in this package.
25 * 25 *
26 * Qt for Windows(R) Licensees 26 * Qt for Win1782dows(R) Licensees
27 * As a special exception, Nokia, as the sole copyright holder for Qt 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 28 * Designer, grants users of the Qt/Eclipse Integration plug-in the
29 * right for the Qt/Eclipse Integration to link to functionality 29 * right for the Qt/Eclipse Integration to link to functionality
30 * provided by Qt Designer and its related libraries. 30 * provided by Qt Designer and its related libraries.
31 * 31 *
770 s << "__nativeId"; 770 s << "__nativeId";
771 } 771 }
772 772
773 if (d_function->isConstructor() && 773 if (d_function->isConstructor() &&
774 ( d_function->implementingClass()->isPolymorphic() 774 ( d_function->implementingClass()->isPolymorphic()
775 || d_function->implementingClass()->typeEntry()->isObject() ) ) { // qtd 775 /*|| d_function->implementingClass()->typeEntry()->isObject()*/ ) ) { // qtd
776 s << "cast(void*) this"; 776 s << "cast(void*) this";
777 if (arguments.count() > 0) 777 if (arguments.count() > 0)
778 s << ", "; 778 s << ", ";
779 } 779 }
780 780
1678 void DGenerator::writeDestructor(QTextStream &s, const AbstractMetaClass *d_class) 1678 void DGenerator::writeDestructor(QTextStream &s, const AbstractMetaClass *d_class)
1679 { 1679 {
1680 if (!d_class->hasConstructors()) 1680 if (!d_class->hasConstructors())
1681 return; 1681 return;
1682 1682
1683 s << " override void __deleteNative() {" << endl 1683 if (d_class->polymorphicBase() == d_class)
1684 << " qtd_" << d_class->name() << "_destructor(__nativeId);" << endl 1684 {
1685 << " }" << endl; 1685 s << " override void __deleteNative() {" << endl
1686 << " qtd_" << d_class->polymorphicBase()->name() << "_delete(__nativeId);" << endl
1687 << " }" << endl;
1688 }
1686 } 1689 }
1687 1690
1688 void DGenerator::writeOwnershipSetter(QTextStream &s, const AbstractMetaClass *d_class) 1691 void DGenerator::writeOwnershipSetter(QTextStream &s, const AbstractMetaClass *d_class)
1689 { 1692 {
1690 if (d_class->isInterface() || d_class->isNamespace()) 1693 if (d_class->isInterface() || d_class->isNamespace())
1691 s << INDENT << "void __nativeOwnership(bool value);"; 1694 {
1695 //s << INDENT << "void __nativeOwnership(bool value);";
1696 }
1692 else if (d_class->typeEntry()->isObject()) 1697 else if (d_class->typeEntry()->isObject())
1693 {// COMPILER BUG: 1698 {// COMPILER BUG:
1694 s << INDENT << "void __nativeOwnership(bool value) { super.__nativeOwnership = value; }"; 1699 //s << INDENT << "void __nativeOwnership(bool value) { super.__nativeOwnership = value; }";
1695 } 1700 }
1696 } 1701 }
1697 1702
1698 1703
1699 void DGenerator::writeSignalHandlers(QTextStream &s, const AbstractMetaClass *d_class) 1704 void DGenerator::writeSignalHandlers(QTextStream &s, const AbstractMetaClass *d_class)
1754 } 1759 }
1755 else if (type->typeEntry()->isObject()) 1760 else if (type->typeEntry()->isObject())
1756 { 1761 {
1757 bool resetAfterUse = !type->isQObject() && signal->resetObjectAfterUse(argument->argumentIndex() + 1); 1762 bool resetAfterUse = !type->isQObject() && signal->resetObjectAfterUse(argument->argumentIndex() + 1);
1758 1763
1759 if ((static_cast<const ComplexTypeEntry*>(type->typeEntry()))->isPolymorphic()) 1764 if (resetAfterUse)
1760 { 1765 s << "auto " << arg_name << " = scopeObject!(" << type->typeEntry()->name() << ")(" << arg_name << ");";
1761 QString flags;
1762 if (resetAfterUse)
1763 flags = "QtdObjectFlags.stackAllocated | QtdObjectFlags.skipNativeDelete";
1764 else
1765 flags = "QtdObjectFlags.none";
1766
1767 s << INDENT << "auto " << arg_name << " = " << type->typeEntry()->name() << ".__wrap(" << arg_name
1768 << ", cast(QtdObjectFlags)(" << flags << "));" << endl;
1769
1770 if (resetAfterUse)
1771 {
1772 s << INDENT << "scope(exit) {" << endl
1773 << INDENT << " if (" << arg_name << "_d_ref.__flags & QtdObjectFlags.stackAllocated)" << endl
1774 << INDENT << " delete " << arg_name << ";" << endl
1775 << INDENT << "}" << endl;
1776 }
1777 }
1778 else 1766 else
1779 { 1767 {
1780 s << INDENT << (resetAfterUse ? "scope " : "auto ") 1768 s << INDENT << "auto " << arg_name << " = " << type->typeEntry()->name() << ".__wrap(" << arg_name
1781 << arg_name << "_d_ref = new " << type->typeEntry()->name() << "(" << arg_name << ", QtdObjectFlags." 1769 << ");" << endl;
1782 << (resetAtferUse ? "skipNativeDelete" : "none") << ");" << endl;
1783 } 1770 }
1784 } 1771 }
1785 1772
1786 s << endl; 1773 s << endl;
1787 } 1774 }
1811 QString auxModName = d_class->package() + "." + d_class->name() + "_aux"; 1798 QString auxModName = d_class->package() + "." + d_class->name() + "_aux";
1812 FileOut auxFile(outputDirectory() + "/" + subDirectoryForClass(d_class) + "/" + d_class->name() + "_aux.d"); 1799 FileOut auxFile(outputDirectory() + "/" + subDirectoryForClass(d_class) + "/" + d_class->name() + "_aux.d");
1813 auxFile.isDone = true; 1800 auxFile.isDone = true;
1814 auxFile.stream << "module " << auxModName << ";" << endl << endl; 1801 auxFile.stream << "module " << auxModName << ";" << endl << endl;
1815 1802
1816 bool staticInit = (d_class->typeEntry()->isObject() && d_class->isPolymorphic()) || (cpp_shared && d_class->generateShellClass() && !d_class->isInterface()); 1803 bool staticInit = d_class->isPolymorphic() || (cpp_shared && d_class->generateShellClass() && !d_class->isInterface());
1817 if (staticInit) 1804 if (staticInit)
1818 { 1805 {
1819 auxFile.isDone = false; 1806 auxFile.isDone = false;
1820 auxFile.stream << "extern(C) void static_init_" << d_class->name() << "();" << endl; 1807 auxFile.stream << "extern(C) void static_init_" << d_class->name() << "();" << endl;
1821 auxFile.stream << "static this() { static_init_" << d_class->name() << "; }" << endl << endl; 1808 auxFile.stream << "static this() { static_init_" << d_class->name() << "; }" << endl << endl;
1919 if (!m_isRecursive) { 1906 if (!m_isRecursive) {
1920 s << "public import qt.QGlobal;" << endl 1907 s << "public import qt.QGlobal;" << endl
1921 << "public import qt.core.Qt;" << endl 1908 << "public import qt.core.Qt;" << endl
1922 << "public import qt.QtdObject;" << endl 1909 << "public import qt.QtdObject;" << endl
1923 << "private import qt.core.QString;" << endl 1910 << "private import qt.core.QString;" << endl
1924 << "private import qt.qtd.Array;" << endl; 1911 << "private import qt.Array;" << endl;
1925 if (d_class->isQObject()) { 1912 if (d_class->isQObject()) {
1926 s << "public import qt.core.QMetaObject;" << endl; 1913 s << "public import qt.core.QMetaObject;" << endl;
1927 s << "public import qt.Signal;" << endl; 1914 s << "public import qt.Signal;" << endl;
1928 if (d_class->name() != "QObject") 1915 if (d_class->name() != "QObject")
1929 s << "public import qt.core.QObject;" << endl; 1916 s << "public import qt.core.QObject;" << endl;
1950 if (dPhobos) 1937 if (dPhobos)
1951 { 1938 {
1952 s << "import std.stdio;" << endl 1939 s << "import std.stdio;" << endl
1953 << "import std.string;" << endl 1940 << "import std.string;" << endl
1954 << "import std.utf;" << endl 1941 << "import std.utf;" << endl
1955 << "import core.memory;" << endl; 1942 << "import core.memory;" << endl
1943 << "import qt.Core;" << endl;
1956 } 1944 }
1957 else 1945 else
1958 { 1946 {
1959 s << "import tango.io.Stdout;" << endl 1947 s << "import tango.io.Stdout;" << endl
1960 << "import tango.stdc.stringz;" << endl 1948 << "import tango.stdc.stringz;" << endl
2021 if (!d_class->isNamespace() && !d_class->isInterface()) { 2009 if (!d_class->isNamespace() && !d_class->isInterface()) {
2022 s << " : "; 2010 s << " : ";
2023 if (d_class->baseClass()) { 2011 if (d_class->baseClass()) {
2024 s << d_class->baseClass()->name(); 2012 s << d_class->baseClass()->name();
2025 } else { 2013 } else {
2026 if (d_class->typeEntry()->isValue()) 2014 if (d_class->isQObject())
2027 s << "QtdObjectBase"; 2015 s << "QtdObjectBase";
2028 else if (d_class->typeEntry()->isObject()) 2016 else
2029 s << "QtdObject"; 2017 s << "QtdObject";
2030
2031 } 2018 }
2032 }/* qtd else if (d_class->isInterface()) { 2019 }/* qtd else if (d_class->isInterface()) {
2033 s << " extends QtJambiInterface"; 2020 s << " extends QtJambiInterface";
2034 }*/ 2021 }*/
2035 2022
2107 /* qtd 2094 /* qtd
2108 if (TypeDatabase::instance()->includeEclipseWarnings()) 2095 if (TypeDatabase::instance()->includeEclipseWarnings())
2109 s << INDENT << "@SuppressWarnings(\"unused\")" << endl; 2096 s << INDENT << "@SuppressWarnings(\"unused\")" << endl;
2110 */ 2097 */
2111 if (actions != ReferenceCount::Set && actions != ReferenceCount::Ignore) { // qtd2 2098 if (actions != ReferenceCount::Set && actions != ReferenceCount::Ignore) { // qtd2
2112 2099 s << INDENT;
2113 s << INDENT; 2100 switch (access) {
2114 switch (access) { 2101 case ReferenceCount::Private:
2115 case ReferenceCount::Private: 2102 s << "package "; break; // qtd
2116 s << "package "; break; // qtd 2103 case ReferenceCount::Protected:
2117 case ReferenceCount::Protected: 2104 s << "protected "; break;
2118 s << "protected "; break; 2105 case ReferenceCount::Public:
2119 case ReferenceCount::Public: 2106 s << "public "; break;
2120 s << "public "; break; 2107 default: // friendly
2121 default: // friendly 2108 break;
2122 } 2109 }
2123
2124 } // qtd2 2110 } // qtd2
2125 2111
2126 if (isStatic) 2112 if (isStatic)
2127 s << "static "; 2113 s << "static ";
2128 2114
2218 foreach (const AbstractMetaField *field, fields) { 2204 foreach (const AbstractMetaField *field, fields) {
2219 if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal())) 2205 if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal()))
2220 writeFieldAccessors(s, field); 2206 writeFieldAccessors(s, field);
2221 } 2207 }
2222 2208
2223 if (d_class->typeEntry()->isObject()) 2209 writeDestructor(s, d_class);
2224 {
2225 if (d_class->isQObject())
2226 writeQObjectFunctions(s, d_class);
2227 else
2228 writeObjectFunctions(s, d_class);
2229
2230 if (d_class->isPolymorphic())
2231 {
2232 s << " static QtdObjectBase __createWrapper(void* nativeId, QtdObjectFlags flags) {" << endl;
2233
2234 QString className = d_class->name();
2235 if (d_class->isAbstract())
2236 className += "_ConcreteWrapper";
2237
2238 s << " auto obj = new(flags) " << className << "(nativeId, flags);" << endl;
2239
2240 if (d_class->isQObject())
2241 s << " qtd_" << d_class->name() << "_createEntity(nativeId, cast(void*)obj);" << endl;
2242
2243 s << " return obj;" << endl
2244 << " }" << endl << endl;
2245 }
2246 }
2247
2248 if (d_class->hasPublicDestructor() && (!d_class->baseClass() || !d_class->hasVirtualFunctions()))
2249 writeDestructor(s, d_class);
2250 2210
2251 // Add dummy constructor for use when constructing subclasses 2211 // Add dummy constructor for use when constructing subclasses
2252 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) { 2212 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) {
2213
2214 writeObjectFunctions(s, d_class);
2215
2253 s << endl 2216 s << endl
2254 << INDENT << "public " 2217 << INDENT << "public "
2255 << "this"; 2218 << "this";
2256 2219
2257 2220
2483 } 2446 }
2484 } 2447 }
2485 s << INDENT << "}" << endl << endl; 2448 s << INDENT << "}" << endl << endl;
2486 } 2449 }
2487 2450
2488 if (d_class->isPolymorphic()) 2451
2452 if (d_class->isPolymorphic() && d_class->polymorphicBase() == d_class)
2489 { 2453 {
2490 if (!d_class->typeEntry()->isQObject()) 2454 s << "extern(C) void* qtd_" << d_class->name() << "_dId(void *nativeId);" << endl << endl;
2491 { 2455 s << "extern(C) void* qtd_" << d_class->name() << "_typeId(void* nativeId);" << endl;
2492 s << "extern(C) void* qtd_" << d_class->name() << "_dId(void *q_ptr);" << endl << endl; 2456 }
2493 s << "extern(C) void* qtd_" << d_class->name() << "_typeId(void* nativeId);" << endl; 2457
2494 } 2458 s << "extern(C) void* qtd_" << d_class->name() << "_staticTypeId();" << endl;
2495
2496 s << "extern(C) void* qtd_" << d_class->name() << "_staticTypeId();" << endl;
2497 }
2498 2459
2499 // if (d_class->needsConversionFunc) 2460 // if (d_class->needsConversionFunc)
2500 // writeConversionFunction(s, d_class); 2461 // writeConversionFunction(s, d_class);
2501 2462
2502 if (d_class->hasConstructors()) 2463 if (d_class->hasConstructors() && d_class->polymorphicBase() == d_class)
2503 s << "extern(C) void qtd_" << d_class->name() << "_destructor(void *ptr);" << endl << endl; 2464 s << "extern(C) void qtd_" << d_class->name() << "_destructor(void *ptr);" << endl << endl;
2504 2465
2505 // qtd 2466 // qtd
2506 s << endl << "// C wrappers" << endl; 2467 s << endl << "// C wrappers" << endl;
2507 d_funcs = d_class->functionsInTargetLang(); 2468 d_funcs = d_class->functionsInTargetLang();
2556 << QString("_initCallBacks(%1);").arg(initArgs) << endl << endl; 2517 << QString("_initCallBacks(%1);").arg(initArgs) << endl << endl;
2557 } 2518 }
2558 2519
2559 s << "extern(C) void static_init_" << d_class->name() << "() {" << endl; 2520 s << "extern(C) void static_init_" << d_class->name() << "() {" << endl;
2560 2521
2561 if (d_class->isPolymorphic()) { 2522 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass)
2562 s << INDENT << "if (!" << d_class->name() << "._staticMetaObject) " << endl 2523 s << " " << d_class->name() << ".__createMetaObject;" << endl << endl;
2563 << INDENT << " " << d_class->name() << ".createStaticMetaObject;" << endl << endl;
2564 }
2565 2524
2566 if (cpp_shared) { 2525 if (cpp_shared) {
2567 // virtual functions 2526 // virtual functions
2568 s << INDENT << "void*[" << virtualFunctions.size() << "] virt_arr;" << endl; 2527 s << INDENT << "void*[" << virtualFunctions.size() << "] virt_arr;" << endl;
2569 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { 2528 for (int pos = 0; pos<virtualFunctions.size(); ++pos) {
2612 m_isRecursive = false; 2571 m_isRecursive = false;
2613 } 2572 }
2614 2573
2615 2574
2616 if (d_class->isQObject()) 2575 if (d_class->isQObject())
2617 { 2576 s << "private extern(C) void qtd_" << d_class->name() << "_createEntity(void* nativeId, void* dId);" << endl << endl;
2618 s << "private extern(C) void* qtd_" << d_class->name() << "_staticMetaObject();" << endl << endl
2619 << "private extern(C) void qtd_" << d_class->name() << "_createEntity(void* nativeId, void* dId);" << endl << endl;
2620 }
2621 } 2577 }
2622 2578
2623 /* 2579 /*
2624 void DGenerator::writeConversionFunction(QTextStream &s, const AbstractMetaClass *d_class) 2580 void DGenerator::writeConversionFunction(QTextStream &s, const AbstractMetaClass *d_class)
2625 { 2581 {
2655 } 2611 }
2656 s << "}" << endl << endl; 2612 s << "}" << endl << endl;
2657 } 2613 }
2658 */ 2614 */
2659 2615
2616 /*
2660 void DGenerator::writeObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class) 2617 void DGenerator::writeObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class)
2661 { 2618 {
2662 // polymorphic 2619 // polymorphic
2663 if (d_class->isPolymorphic()) 2620 if (d_class->isPolymorphic())
2664 { 2621 {
2701 "qtd_" << rootClassName << "_typeId(nativeId), flags));" << endl 2658 "qtd_" << rootClassName << "_typeId(nativeId), flags));" << endl
2702 << " return obj;" << endl 2659 << " return obj;" << endl
2703 << " }" << endl << endl; 2660 << " }" << endl << endl;
2704 } 2661 }
2705 else 2662 else
2706 { 2663 {
2707 s << " static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl 2664 }
2708 << " return new " << d_class->name() << "(nativeId, flags);" 2665 }
2709 << " }" << endl << endl; 2666 */
2710 } 2667
2711 } 2668 void DGenerator::writeObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class)
2712
2713 void DGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class)
2714 { 2669 {
2715 QString concreteArg; 2670 QString concreteArg;
2716 if (d_class->isAbstract()) 2671 if (d_class->isAbstract())
2717 concreteArg += ", " + d_class->name() + "_ConcreteWrapper"; 2672 concreteArg += ", " + d_class->name() + "_ConcreteWrapper";
2718 2673
2719 s << " private static QMetaObject _staticMetaObject;" << endl 2674 bool isQObject = d_class->isQObject();
2720 << " protected static void createStaticMetaObject() {" << endl 2675 QString moName = isQObject ? "QMetaObject" : "QtdMetaObject";
2721 << " assert(!_staticMetaObject);" << endl 2676
2722 << " QMetaObject base;" << endl; 2677 s << " private static __gshared " << moName << " _staticMetaObject;" << endl
2723 2678 << " static void __createMetaObject(){" << endl
2724 if (d_class->name() != "QObject") 2679 << " if (!_staticMetaObject){" << endl
2680 << " QtdMetaObjectBase base;" << endl
2681 << " static if (is(typeof(super.__createMetaObject))) {" << endl
2682 << " alias typeof(super) Base;" << endl
2683 << " Base.__createMetaObject();" << endl
2684 << " base = Base._staticMetaObject;" << endl
2685 << " }" << endl
2686 << " _staticMetaObject = new " << moName << "(qtd_" << d_class->name() << "_staticTypeId, base, &__createWrapper);" << endl
2687 << " }" << endl
2688 << " }" << endl << endl
2689
2690 << " " << moName << " metaObject(){" << endl
2691 << " return _staticMetaObject;" << endl
2692 << " }" << endl << endl
2693 << " static " << moName << " staticMetaObject() {" << endl
2694 << " return _staticMetaObject;" << endl
2695 << " }" << endl << endl
2696
2697 << " static QtdObjectBase __createWrapper(void* nativeId, QtdObjectFlags flags) {" << endl;
2698
2699 QString className = d_class->name();
2700 if (d_class->isAbstract())
2701 className += "_ConcreteWrapper";
2702
2703 s << " auto obj = new(flags) " << className << "(nativeId, flags);" << endl;
2704
2705 if (d_class->isQObject())
2706 s << " qtd_" << d_class->name() << "_createEntity(nativeId, cast(void*)obj);" << endl;
2707
2708 s << " return obj;" << endl
2709 << " }" << endl << endl;
2710
2711 if (!isQObject)
2712 {
2713 if (d_class->isPolymorphic())
2714 {
2715 const AbstractMetaClass* polyBase = d_class->polymorphicBase();
2716 s << " static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl
2717 << " auto obj = cast(" << d_class->name() << ") qtd_" << polyBase->name() << "_dId(nativeId);" << endl
2718 << " if (!obj)" << endl
2719 << " obj = static_cast!(" << d_class->name() << ")(_staticMetaObject.wrap(nativeId, "
2720 "qtd_" << polyBase->name() << "_typeId(nativeId), flags));" << endl
2721 << " return obj;" << endl
2722 << " }" << endl << endl;
2723 }
2724 else
2725 {
2726 s << " static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl
2727 << " return new(flags) " << d_class->name() << "(nativeId, flags);" << endl
2728 << " }" << endl << endl;
2729 }
2730 }
2731 else
2725 { 2732 {
2726 QString baseName = d_class->baseClassName(); 2733 s << " static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl
2727 s << " if (!" << baseName << "._staticMetaObject)" << endl 2734 << " return static_cast!" << d_class->name() << "(" << d_class->name() << "._staticMetaObject.wrap(nativeId, flags));" << endl
2728 << " " << baseName << ".createStaticMetaObject;" << endl 2735 << " }" << endl << endl;
2729 << " base = " << baseName << "._staticMetaObject;" << endl; 2736 }
2730 }
2731
2732 s << " _staticMetaObject = new QMetaObject(qtd_" << d_class->name() << "_staticMetaObject, base);" << endl
2733 << " _staticMetaObject.construct!(" << d_class->name() << concreteArg << ");" << endl
2734 << " }" << endl << endl
2735
2736 << " QMetaObject metaObject() {" << endl
2737 << " return _staticMetaObject;" << endl
2738 << " }" << endl << endl
2739
2740 << " static QMetaObject staticMetaObject() {" << endl
2741 << " return _staticMetaObject;" << endl
2742 << " }" << endl << endl
2743
2744 << " static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl
2745 << " return static_cast!(" << d_class->name() << ")(_staticMetaObject.wrap(nativeId, flags));" << endl
2746 << " }" << endl << endl;
2747 } 2737 }
2748 2738
2749 /* 2739 /*
2750 void DGenerator::writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class) 2740 void DGenerator::writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class)
2751 { 2741 {
2906 continue; 2896 continue;
2907 else if (type->typeEntry()->isObject()) 2897 else if (type->typeEntry()->isObject())
2908 { 2898 {
2909 bool resetAfterUse = !type->isQObject() && d_function->resetObjectAfterUse(argument->argumentIndex() + 1); 2899 bool resetAfterUse = !type->isQObject() && d_function->resetObjectAfterUse(argument->argumentIndex() + 1);
2910 2900
2911 if ((static_cast<const ComplexTypeEntry*>(type->typeEntry()))->isPolymorphic()) 2901
2912 { 2902 if (resetAfterUse)
2913 QString flags; 2903 s << INDENT << "auto " << arg_name << "_d_ref = scopeObject!(" << type->typeEntry()->name() << ")(" << arg_name << ");";
2914 if (resetAfterUse)
2915 flags = "QtdObjectFlags.stackAllocated | QtdObjectFlags.skipNativeDelete";
2916 else
2917 flags = "QtdObjectFlags.none";
2918
2919 s << INDENT << "auto " << arg_name << "_d_ref = " << type->typeEntry()->name() << ".__wrap(" << arg_name
2920 << ", cast(QtdObjectFlags)(" << flags << "));" << endl;
2921
2922 if (resetAfterUse)
2923 {
2924 s << INDENT << "scope(exit) {" << endl
2925 << INDENT << " if (" << arg_name << "_d_ref.__flags & QtdObjectFlags.stackAllocated)" << endl
2926 << INDENT << " delete " << arg_name << ";" << endl
2927 << INDENT << "}" << endl;
2928 }
2929 }
2930 else 2904 else
2931 { 2905 {
2932 s << INDENT << (resetAfterUse ? "scope " : "auto ") 2906 s << INDENT << "auto " << arg_name << "_d_ref = " << type->typeEntry()->name() << ".__wrap(" << arg_name
2933 << arg_name << "_d_ref = new " << type->typeEntry()->name() << "(" << arg_name << ", QtdObjectFlags." 2907 << ");" << endl;
2934 << (resetAtferUse ? "skipNativeDelete" : "none") << ");" << endl;
2935 } 2908 }
2936 } 2909 }
2937 else 2910 else
2938 qFatal(qPrintable(type->typeEntry()->name())); 2911 qFatal(qPrintable(type->typeEntry()->name()));
2939 2912