changeset 259:515d6e1c7b10 lifetime

another iteration
author maxter
date Thu, 17 Sep 2009 16:28:41 +0000
parents 1da8870e9a62
children b5773ccab07d
files generator/abstractmetabuilder.cpp generator/abstractmetalang.cpp generator/abstractmetalang.h generator/containergenerator.cpp generator/cppheadergenerator.cpp generator/cppimplgenerator.cpp generator/dgenerator.cpp generator/dgenerator.h generator/typesystem.h qt/core/QMetaObject.d qt/d1/qt/QtdObject.d
diffstat 11 files changed, 165 insertions(+), 267 deletions(-) [+]
line wrap: on
line diff
--- a/generator/abstractmetabuilder.cpp	Wed Sep 16 14:16:33 2009 +0000
+++ b/generator/abstractmetabuilder.cpp	Thu Sep 17 16:28:41 2009 +0000
@@ -58,6 +58,8 @@
 #include <QtCore/QTextStream>
 #include <QtCore/QVariant>
 
+#include <iostream>
+
 static QString strip_template_args(const QString &name)
 {
     int pos = name.indexOf('<');
@@ -1310,8 +1312,18 @@
                 meta_class->setHasNonPrivateConstructor(true);
             }
 
-            if (meta_function->isDestructor() && !meta_function->isFinal())                            
-                meta_class->setHasVirtualDestructor(true);            
+            if (meta_function->isDestructor())
+            {
+                if (meta_class->name() == "QFSFileEngine")
+                {
+                    std::cout << meta_function->isFinal() << std::endl;
+                    std::cout << qPrintable(meta_function->name()) << std::endl;
+                    qFatal("Gop");
+                }
+               
+                if (!meta_function->isFinal())
+                    meta_class->setHasVirtualDestructor(true);            
+            }
 
             if (!meta_function->isDestructor()
                 && !meta_function->isInvalid()
--- a/generator/abstractmetalang.cpp	Wed Sep 16 14:16:33 2009 +0000
+++ b/generator/abstractmetalang.cpp	Thu Sep 17 16:28:41 2009 +0000
@@ -1326,11 +1326,6 @@
     return queryFunctions(Constructors).size() != 0;
 }
 
-bool AbstractMetaClass::isPolymorphic()
-{
-    return typeEntry()->isObject() && m_has_virtual_destructor;
-}
-
 void AbstractMetaClass::addDefaultConstructor()
 {
     AbstractMetaFunction *f = new AbstractMetaFunction;
--- a/generator/abstractmetalang.h	Wed Sep 16 14:16:33 2009 +0000
+++ b/generator/abstractmetalang.h	Thu Sep 17 16:28:41 2009 +0000
@@ -854,8 +854,6 @@
 
     void setTypeAlias(bool typeAlias) { m_is_type_alias = typeAlias; }
     bool isTypeAlias() const { return m_is_type_alias; }
-    
-    bool isPolymorphic();
 
     const QStringList &depends() { return m_type_entry->depends(); }
 
--- a/generator/containergenerator.cpp	Wed Sep 16 14:16:33 2009 +0000
+++ b/generator/containergenerator.cpp	Thu Sep 17 16:28:41 2009 +0000
@@ -473,7 +473,7 @@
       << "package " << d_type << " qtd_" << cls_name << "_cpp_to_d(" << cpp_type << " ret)" << endl
       << "{" << endl;
 
-    marshallFromCppToD(s, centry);
+    marshalToD(s, centry);
 
     s << "}" << endl;
 }
--- a/generator/cppheadergenerator.cpp	Wed Sep 16 14:16:33 2009 +0000
+++ b/generator/cppheadergenerator.cpp	Thu Sep 17 16:28:41 2009 +0000
@@ -44,6 +44,7 @@
 #include <QtCore/QDir>
 
 #include <qdebug.h>
+#include <iostream>
 
 QString CppHeaderGenerator::fileNameForClass(const AbstractMetaClass *java_class) const
 {
@@ -175,12 +176,19 @@
         priGenerator->addHeader(java_class->package(), fileNameForClass(java_class));
         return ;
     }
+    
+    if (java_class->name() == "QFSFileEngine")
+    {
+        std::cout << java_class->typeEntry()->isObject() << std::endl;
+        std::cout << java_class->hasVirtualDestructor() << std::endl;
+        qFatal("Bo");
+    }
 
     s << "class " << shellClassName(java_class)
       << " : public " << java_class->qualifiedCppName();
     if (java_class->isQObject())
         s << ", public QtD_QObjectEntity";
-    else if (java_class->hasVirtualFunctions())
+    else if (java_class->hasVirtualDestructor())
         s << ", public QtD_Entity";
     s << endl  << "{" << endl;
 
@@ -208,7 +216,7 @@
             writeFunction(s, function);
     }
     
-    if (java_class->hasVirtualFunctions())
+    if (java_class->typeEntry()->isObject() && java_class->hasVirtualDestructor())
         s << "    ~" << shellClassName(java_class) << "();" << endl << endl;
     
 
--- a/generator/cppimplgenerator.cpp	Wed Sep 16 14:16:33 2009 +0000
+++ b/generator/cppimplgenerator.cpp	Thu Sep 17 16:28:41 2009 +0000
@@ -601,7 +601,7 @@
                 writeShellConstructor(s, function);
         }
         
-        if (java_class->typeEntry()->isObject())
+        if (java_class->hasVirtualDestructor())
             writeShellDestructor(s, java_class);
 
         if (java_class->isQObject())
@@ -1391,7 +1391,7 @@
     
     if (cls->isQObject())
         s << "," << endl << "      QtD_QObjectEntity(this, d_ptr)";
-    else if (cls->typeEntry()->isObject() && cls->hasVirtualFunctions())
+    else if (cls->hasVirtualDestructor())
         s << "," << endl << "      QtD_Entity(d_ptr)";
 /* qtd        s << "    m_meta_object(0)," << endl;
     s << "      m_vtable(0)," << endl
@@ -1736,16 +1736,16 @@
 
 void CppImplGenerator::writeObjectFunctions(QTextStream &s, const AbstractMetaClass *java_class)
 {
-    s << "extern \"C\" DLL_PUBLIC const void* qtd_" << java_class->name() << "_staticTypeId()" << endl;
-    s << "{" << endl;
+    if (java_class->hasVirtualDestructor())
     {
-        Indentation indent(INDENT);
-            s << INDENT << "return &typeid(" << java_class->qualifiedCppName() << ");" << endl;
-    }
-    s << "}" << endl << endl;
+        s << "extern \"C\" DLL_PUBLIC const void* qtd_" << java_class->name() << "_staticTypeId()" << endl;
+        s << "{" << endl;
+        {
+            Indentation indent(INDENT);
+                s << INDENT << "return &typeid(" << java_class->qualifiedCppName() << ");" << endl;
+        }
+        s << "}" << endl << endl;
         
-    if (java_class->hasVirtualFunctions())
-    {
         if (!java_class->baseClass())
         {      
             s << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_dId(void *q_ptr)" << endl;
@@ -1767,9 +1767,7 @@
                     s << INDENT << "return &typeid((" << java_class->qualifiedCppName() << "*)nativeId);" << endl;
             }
             s << "}" << endl << endl;
-        }
-        else
-            s << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->rootClass()->name() << "_dId(void *q_ptr);" << endl;            
+        }       
     }
 }
 
--- a/generator/dgenerator.cpp	Wed Sep 16 14:16:33 2009 +0000
+++ b/generator/dgenerator.cpp	Thu Sep 17 16:28:41 2009 +0000
@@ -899,9 +899,7 @@
             s << return_type->name() << ".__wrap(ret);" << endl;
         
 
-        if (return_type->isValue() && !return_type->typeEntry()->isStructInD()
-            || return_type->isNativePointer() && return_type->typeEntry()->isValue()
-            || return_type->name() == "QVariant")
+        if (return_type->isValue() && !return_type->typeEntry()->isStructInD())
             s << "new " << return_type->name() << "(ret);" << endl;
         
         if (return_type->isObject()) {
@@ -1790,7 +1788,7 @@
     auxFile.isDone = true;
     auxFile.stream << "module " << auxModName << ";" << endl << endl;
 
-    bool staticInit = (d_class->typeEntry()->isObject() && d_class->hasVirtualFunctions()) || (cpp_shared && d_class->generateShellClass() && !d_class->isInterface());
+    bool staticInit = (d_class->typeEntry()->isObject() && d_class->hasVirtualDestructor()) || (cpp_shared && d_class->generateShellClass() && !d_class->isInterface());
     if (staticInit)
     {
         auxFile.isDone = false;
@@ -2200,19 +2198,27 @@
             writeFieldAccessors(s, field);
     }
 
-    if (d_class->typeEntry()->isObject() && d_class->hasVirtualFunctions())
+    if (d_class->typeEntry()->isObject())
     {
         if (d_class->isQObject())
             writeQObjectFunctions(s, d_class);
         else
             writeObjectFunctions(s, d_class);
-    
-        s << "    static QtdObjectBase __createWrapper(void* nativeId, QtdObjectFlags flags) {" << endl
-          << "        return new(flags) " << d_class->name() << "(nativeId, flags);" << endl
-          << "    }" << endl << endl;
+        
+        if (d_class->hasVirtualDestructor())
+        {    
+          s << "    static QtdObjectBase __createWrapper(void* nativeId, QtdObjectFlags flags) {" << endl
+            << "        auto obj = new(flags) " << d_class->name() << "(nativeId, flags);" << endl;
+            
+            if (d_class->isQObject())
+               s << "        qtd_" << d_class->name() << "_createEntity(nativeId, cast(void*)obj);" << endl;
+            
+          s << "        return obj;" << endl
+            << "    }" << endl << endl;
+        }
     }
     
-    if (d_class->hasPublicDestructor() && (!d_class->baseClass() || !d_class->hasVirtualFunctions()))
+    if (d_class->hasPublicDestructor() && (!d_class->baseClass() || !d_class->hasVirtualDestructor()))
         writeDestructor(s, d_class);
 
     // Add dummy constructor for use when constructing subclasses
@@ -2224,18 +2230,10 @@
 
         Indentation indent(INDENT);
         
-       
         QString flags = d_class->hasVirtualFunctions() && d_class->typeEntry()->isObject() ? "QtdObjectFlags.hasDId" : "QtdObjectFlags.none";
         s << "(void* nativeId, QtdObjectFlags flags = " << flags << ") {" << endl
         << INDENT << "super(nativeId, flags);" << endl;
         
-        if (d_class->name() == "QObject")
-        {
-            s << INDENT << "if (!(__flags & QtdObjectFlags.hasDId))" << endl
-            << INDENT << "    __createEntity;" << endl;
-        }
-        
-        
         /*
         if (cpp_shared) {
             if (d_class->generateShellClass() && !d_class->isInterface())
@@ -2460,7 +2458,7 @@
         s  << INDENT << "}" << endl << endl;
     }
 
-    if (d_class->typeEntry()->isObject() && d_class->hasVirtualFunctions())
+    if (d_class->typeEntry()->isObject() && d_class->hasVirtualDestructor())
     {
         if (!d_class->typeEntry()->isQObject())
         {
@@ -2533,7 +2531,7 @@
 
         s << "extern(C) void static_init_" << d_class->name() << "() {" << endl;
 
-        if (d_class->typeEntry()->isObject() && d_class->hasVirtualFunctions()) {
+        if (d_class->typeEntry()->isObject() && d_class->hasVirtualDestructor()) {
             s << INDENT << "if (!" << d_class->name() << "._staticMetaObject) " << endl
             << INDENT << "    " << d_class->name() << ".createStaticMetaObject;" << endl << endl;
         }
@@ -2632,57 +2630,57 @@
 }
 */
 
-// Polymorphic non-QObject
 void DGenerator::writeObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class)
 {   
-    QString rootClassName = d_class->rootClass()->name();
-    QString concreteArg;
-    if (d_class->isAbstract())
-        concreteArg += ", " + d_class->name() + "_ConcreteWrapper";      
-
-  s << "    private static QtdMetaObject _staticMetaObject;" << endl
-    //<< "    private static QtdMetaObject[void*] _nativeToTargetMap;" << endl
-    
-    << "    protected static void createStaticMetaObject() {" << endl
-    << "        assert(!_staticMetaObject);" << endl
-    << "        QtdMetaObject base;" << endl;
-
-    if (d_class->baseClass())
+    // polymorphic
+    if (d_class->hasVirtualDestructor())
     {
-        QString baseName = d_class->baseClassName();
-        s << "        if (!" << baseName << "._staticMetaObject)" << endl
-        << "            " << baseName << ".createStaticMetaObject;" << endl
-        << "        base = " << baseName << "._staticMetaObject;" << endl;
+        QString rootClassName = d_class->rootClass()->name();
+        QString concreteArg;
+        if (d_class->isAbstract())
+            concreteArg += ", " + d_class->name() + "_ConcreteWrapper";      
+
+    s << "    private static QtdMetaObject _staticMetaObject;" << endl
+        //<< "    private static QtdMetaObject[void*] _nativeToTargetMap;" << endl
+        
+        << "    protected static void createStaticMetaObject() {" << endl
+        << "        assert(!_staticMetaObject);" << endl
+        << "        QtdMetaObject base;" << endl;
+
+        if (d_class->baseClass())
+        {
+            QString baseName = d_class->baseClassName();
+            s << "        if (!" << baseName << "._staticMetaObject)" << endl
+            << "            " << baseName << ".createStaticMetaObject;" << endl
+            << "        base = " << baseName << "._staticMetaObject;" << endl;
+        }
+        
+        s << "        _staticMetaObject = new QtdMetaObject(qtd_" << d_class->name() << "_staticTypeId, base);"   << endl
+        << "        _staticMetaObject.construct!(" << d_class->name() << concreteArg << ");" << endl
+        << "    }" << endl << endl
+
+        << "    QtdMetaObject metaObject() {" << endl
+        << "        return _staticMetaObject;" << endl
+        << "    }" << endl << endl
+        
+        << "    static QtdMetaObject staticMetaObject() {" << endl
+        << "        return _staticMetaObject;" << endl
+        << "    }" << endl << endl
+
+        << "    static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.skipNativeDelete) {" << endl
+        << "        auto obj = cast("  << d_class->name() << ") qtd_" << rootClassName << "_dId(nativeId);" << endl
+        << "        if (!obj)" << endl
+        << "            obj = static_cast!(" << d_class->name() << ")(_staticMetaObject.wrap(nativeId,"
+                            "qtd_" << rootClassName << "_typeId(nativeId), flags));" << endl
+        << "        return obj;" << endl                   
+        << "    }" << endl << endl;   
     }
-    
-    s << "        _staticMetaObject = new QtdMetaObject(qtd_" << d_class->name() << "_staticTypeId, base);"   << endl
-    << "        _staticMetaObject.construct!(" << d_class->name() << concreteArg << ");" << endl
-    << "    }" << endl << endl
-
-    << "    QtdMetaObject metaObject() {" << endl
-    << "        return _staticMetaObject;" << endl
-    << "    }" << endl << endl
-    
-    << "    static QtdMetaObject staticMetaObject() {" << endl
-    << "        return _staticMetaObject;" << endl
-    << "    }" << endl << endl
-
-    << "    static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.skipNativeDelete) {" << endl
-    << "        auto obj = cast("  << d_class->name() << ") qtd_" << rootClassName << "_dId(nativeId);" << endl
-    << "        if (!obj)" << endl
-    << "            obj = static_cast!(" << d_class->name() << ")(_staticMetaObject.wrap(nativeId,"
-                        "qtd_" << rootClassName << "_typeId(nativeId), flags));" << endl
-    << "        return obj;" << endl                   
-    << "    }" << endl << endl;
-    /*
-    << "    overrive protected void __addMapping() {" << endl
-    << "        _nativeToTargetMap[__nativeId] = this;" << endl
-    << "    }" << endl << endl
-    
-    << "    override protected void __removeMapping() {" << endl
-    << "        _nativeToTargetMap.remove(__nativeId);" << endl
-    << "    }" << endl << endl
-    */  
+    else
+    {
+      s << "    static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.skipNativeDelete) {" << endl
+        << "        return new " << d_class->name() << "(nativeId, flags);"
+        << "    }" << endl << endl;
+    }
 }
 
 void DGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class)
@@ -2718,11 +2716,7 @@
 
     << "    static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl
     << "        return static_cast!(" << d_class->name() << ")(_staticMetaObject.wrap(nativeId, flags));" << endl
-    << "    }" << endl << endl
-
-    << "    void __createEntity() {" << endl
-    << "        return qtd_" << d_class->name() << "_createEntity(__nativeId, cast(void*)this);" << endl
-    << "    }" << endl << endl;
+    << "    }" << endl << endl;    
 }
 
 /*
@@ -2732,61 +2726,23 @@
 }
 */
 
-// Returns the name of the resulting variable
-QString DGenerator::marshalToD(QTextStream &s, QString argName, const TypeEntry* type, MarshalFlags flags)
+void DGenerator::marshalToD(QTextStream &s, const ComplexTypeEntry *ctype)
 {
-    if (type->isBasicValue())
-        return argName;
-         
-    QString qtdObjFlags = "QtdObjectFlags.none";    
-    const ObjectTypeEntry *ctype = 0;
-    bool stackObject = false;   
-    
-    if (type->isObject())
-        ctype = static_cast<const ObjectTypeEntry *>(ctype);
-    
-    if (type->isValue())
-        flags |= MarshalScope;  
-    
-    if (flags & MarshalScope)
-    {
-        if (type->isObject() && type->hasVirtualDestructor())
-        {
-            qtdObjectFlags += " | QtdObjectFlags.stackAllocated";
-            bool stackObject = true;
-        }
-        else
-            s << INDENT << "scope ";
-        
-        qtdObjectFlags += "| QtdObjectFlags.skipNativeDelete";
-    }
-    else
-        s << INDENT << "auto ";
-    
-    s << resultName << " = ";        
-    
-            
-    if (ctype->isObject() && type->hasVirtualDestructor()) {        
-        exp = type->name() + ".__wrap(ret);" + endl;
-    }
-    else if (type->isValue())
-    {
-        if (type->actualIndirections() == 0)
-            s << "new " << type->name() << "(" << argName << ");" << endl;
-        else if (type->actualIndirections() == 1)
-            s << "new "         
-    }
-            
-    
+    if(ctype->isQObject()) {
+        QString type_name = ctype->name();
+        if (ctype->isAbstract())
+            type_name += "_ConcreteWrapper";
+        s << "return " << type_name << ".__getObject(ret);" << endl;
+    } else if (ctype->isValue() && !ctype->isStructInD()) {
+        s << INDENT << "return new " << ctype->name() << "(ret);" << endl;
+    } else if (ctype->isVariant()) {
+        s << INDENT << "return new QVariant(ret);" << endl;
     } else if (ctype->name() == "QModelIndex" || ctype->isStructInD()) {
         s << INDENT << "return ret;" << endl;
+    } else if (ctype->isObject()) {
+        QString type_name = ctype->name();
+        s << "return qtd_" << type_name << "_from_ptr(ret);" << endl;
     }
-    
-    if (stackObject)
-    {
-        s << ""
-    }
-    
 }
 
 void DGenerator::writeNativeField(QTextStream &s, const AbstractMetaField *field)
@@ -2922,50 +2878,41 @@
                 }
                 else if (type->typeEntry()->isStructInD())
                     continue;
-                else if ((type->typeEntry()->isValue() && type->isNativePointer())
-                    || type->isValue() || type->isVariant()){
-                    s << INDENT << "scope " << arg_name << "_d_ref = new " << type->typeEntry()->name() << "(" << arg_name << ");" << endl;
-                
-                    (*logstream) << type->name() << ", " << argument->argumentIndex() + 1 << ", "
-                            << implementor->name() << "::" <<  d_function->name();
-                
-                    if (type->typeEntry()->isValue())                    
-                        (*logstream) << ", type entry value";
-                    
-                    if (type->typeEntry()->isValue())                    
-                        (*logstream) << ", value";
-                    
-                    if (type->isNativePointer())                    
-                        (*logstream) << ", native pointer";
-                    
-                    const ComplexTypeEntry* ctype = dynamic_cast<const ComplexTypeEntry*>(type->typeEntry());
-                    if (ctype && ctype->hasVirtualFunctions())                    
-                        (*logstream) << ", polymorphic";
-                    
-                    (*logstream) << endl;
+                else if (type->typeEntry()->isValue()){
+                    s << INDENT << "scope " << arg_name << "_d_ref = new " << type->typeEntry()->name() << "(" << arg_name << ", QtdObjectFlags.skipNativeDelete);" << endl;
                 }                
                 else if (!type->hasNativeId())
                     continue;
                 else if (type->isObject() || type->isQObject())
-                {
-                    if (!type->isQObject())
+                {            
+                    bool resetAfterUse = !type->isQObject() && d_function->resetObjectAfterUse(argument->argumentIndex() + 1);
+                    
+                    if ((static_cast<const ComplexTypeEntry*>(type->typeEntry()))->hasVirtualDestructor())
+                    {   
+                        QString flags;
+                        if (resetAfterUse)
+                            flags += "QtdObjectFlags.stackAllocated | QtdObjectFlags.skipNativeDelete";
+                        else if (type->isQObject())
+                            flags += "QtdObjectFlags.none";
+                        else
+                            flags = "QtdObjectFlags.skipNativeDelete";
+                        
+                        s << INDENT << "auto " << arg_name << "_d_ref = " << type->typeEntry()->name() << ".__wrap(" << arg_name
+                            << ", " << flags << ");" << endl;
+                        
+                        if (resetAfterUse)
+                        {
+                            s << INDENT << "scope(exit) {" << endl
+                              << INDENT << "    if (" << arg_name << "_d_ref.__flags & QtdObjectFlags.stackAllocated)" << endl
+                              << INDENT << "        delete " << arg_name << ";" << endl
+                              << INDENT << "}" << endl;
+                        }
+                    }                                       
+                    else
                     {
-                        (*logstream) << type->name() << ", " << argument->argumentIndex() + 1 << ", "
-                            << implementor->name() << "::" <<  d_function->name();
-                    
-                        (*logstream) << ", object";
-                            
-                        const ComplexTypeEntry* ctype = dynamic_cast<const ComplexTypeEntry*>(type->typeEntry());
-                        if (ctype && ctype->hasVirtualFunctions())                    
-                            (*logstream) << ", polymorphic";
-                        
-                        (*logstream) << endl;
+                        s << INDENT << (resetAfterUse ? "scope " : "auto ")
+                          << arg_name << "_d_ref = new " << type->typeEntry()->name() << "(" << arg_name << ", QtdObjectFlags.skipNativeDelete);";
                     }
-                
-                    if (((ComplexTypeEntry*)type->typeEntry())->hasVirtualFunctions() || !d_function->resetObjectAfterUse(argument->argumentIndex() + 1))
-                        s << INDENT << "auto " << arg_name << "_d_ref = " << type->typeEntry()->name() << ".__wrap(" << arg_name << ");";
-                    else
-                        s << INDENT << "scope " << arg_name << "_d_ref = new " << type->typeEntry()->name() << "(" << arg_name << ", QtdObjectFlags.skipNativeDelete);";
                 }
                 else
                     qFatal(qPrintable(type->typeEntry()->name()));
@@ -3073,24 +3020,6 @@
     log = new QFile("arglog.txt");
     log->open(QFile::ReadWrite);
     logstream = new QTextStream(log);
-    // qtd
-    // code for including classses in 1 module for avoiding circular imports
-    foreach (AbstractMetaClass *cls, m_classes) {
-        ComplexTypeEntry *ctype = const_cast<ComplexTypeEntry *>(cls->typeEntry());
-
-        if (!cls->isInterface() && cls->isAbstract())            
-            ctype->setAbstract(true);
-                
-        ctype->setHasVirtualFunctions(cls->hasVirtualFunctions());
-
-        foreach(QString child, ctype->includedClasses) {
-            ComplexTypeEntry *ctype_child = TypeDatabase::instance()->findComplexType(child);
-            ctype_child->addedTo = cls->name();
-        }
-
-        foreach (AbstractMetaFunction *function, cls->functions())
-            function->checkStoreResult();
-    }
 
     Generator::generate();
 
--- a/generator/dgenerator.h	Wed Sep 16 14:16:33 2009 +0000
+++ b/generator/dgenerator.h	Thu Sep 17 16:28:41 2009 +0000
@@ -138,12 +138,6 @@
 
     void writeShellVirtualFunction(QTextStream &s, const AbstractMetaFunction *function,
                                           const AbstractMetaClass *implementor, int id);
-                                          
-    enum MarshalFlags
-    {        
-        MarhsalScope    = 0x1
-    }
-    
     void marshalToD(QTextStream &s, const ComplexTypeEntry* ctype);
 
 private:
--- a/generator/typesystem.h	Wed Sep 16 14:16:33 2009 +0000
+++ b/generator/typesystem.h	Thu Sep 17 16:28:41 2009 +0000
@@ -886,6 +886,10 @@
 
     bool hasVirtualFunctions() const { return m_hasVirtualFunctions; }
     void setHasVirtualFunctions(bool value) { m_hasVirtualFunctions = value; }
+    
+    bool hasVirtualDestructor() const { return m_hasVirtualDestructor; }
+    void setHasVirtualDestructor(bool value) { m_hasVirtualDestructor = value; }
+
 
     void setDepends(const QStringList &depends) {m_depends = depends; }
     const QStringList &depends() {return m_depends; }
@@ -920,6 +924,7 @@
     bool m_isStructInD;
     bool m_isAbstract;
     bool m_hasVirtualFunctions;
+    bool m_hasVirtualDestructor;
     QStringList m_depends;
 };
 
--- a/qt/core/QMetaObject.d	Wed Sep 16 14:16:33 2009 +0000
+++ b/qt/core/QMetaObject.d	Thu Sep 17 16:28:41 2009 +0000
@@ -4,56 +4,20 @@
 import qt.core.QObject;
 import qt.QtdObject;
 
-final class QMetaObject
+/++
+    Meta-object for QObject classes.
++/
+final class QMetaObject : MetaObject
 {
-    private
-    {
-        void* _nativeId;
-        QMetaObject _base; // super class
-        QMetaObject _firstDerived; // head of the linked list of derived classes
-        QMetaObject _next; // next sibling on this derivation level
-        ClassInfo _classInfo;
-
-        QObject function(void* nativeId) _createWrapper;
-    }
+    alias typeof(this) This;
     
-    private void addDerived(QMetaObject mo)
-    {
-        mo._next = _firstDerived;
-        _firstDerived = mo;
-    }
+    private void* _nativeId;
     
-    // NOTE: construction is split between this non-templated constructor and 'construct' function below.
     this(void* nativeId, QMetaObject base)
     {
         _nativeId = nativeId;
-        if (base)
-        {
-            base.addDerived(this);
-            _base = base;
-        }
-    }
-    
-    // TODO: remove when D acquires templated constructors       
-    void construct(T : QObject, Concrete = T)()
-    {
-        _classInfo = T.classinfo;        
-
-        _createWrapper = function QObject(void* nativeId) {
-                // COMPILER BUG: cast is should not be needed
-                auto obj = new Concrete(nativeId, cast(QtdObjectFlags)(QtdObjectFlags.nativeOwnership | QtdObjectFlags.dynamicEntity));
-                // TODO: Probably this should be a virtual call from T's constructor
-                T.__createEntity(nativeId, cast(void*)obj);
-                return obj;
-            };
-    }
-    
-    /++
-    +/
-    QMetaObject base()
-    {
-        return _base;
-    }
+        super(base);
+    }    
     
     /++
     +/
@@ -61,19 +25,12 @@
     {
         return _nativeId;
     }
-
-    /++
-    +/
-    ClassInfo classInfo()
-    {
-        return _classInfo;
-    }
     
     private QMetaObject lookupDerived(void*[] moIds)
     {
         assert (moIds.length >= 1);
                 
-        for (auto mo = _firstDerived; mo !is null; mo = mo._next)
+        for (auto mo = static_cast!(This)(firstDerived); mo !is null; mo = static_cast!(This)(mo.next))
         {
             if (mo._nativeId == moIds[0])
             {
@@ -89,7 +46,7 @@
         return this;
     }
     
-    QObject getObject(void* nativeObjId)
+    QObject wrap(void* nativeObjId, QtdObjectFlags flags = QtdObjectFlags.none)
     {
         QObject result;
         
@@ -100,7 +57,7 @@
             {
                 auto moId = qtd_QObject_metaObject(nativeObjId);
                 if (_nativeId == moId)
-                     result = _createWrapper(nativeObjId);
+                     result = _createWrapper(nativeObjId, flags);
                 else
                 {
                     // get native metaobjects for the entire derivation lattice
@@ -110,7 +67,9 @@
                     for (void* tmp = moId;;)
                     {
                         tmp = qtd_QMetaObject_superClass(tmp);                        
-                        assert(tmp);
+                        if (!tmp)
+                            return null;
+                        
                         if (tmp == _nativeId)                        
                             break;
                         moCount++;
@@ -122,7 +81,7 @@
                     while (moCount > 0)
                         moIds[--moCount] = moId = qtd_QMetaObject_superClass(moId);
                                     
-                    result = lookupDerived(moIds)._createWrapper(nativeObjId);
+                    result = lookupDerived(moIds)._createWrapper(nativeObjId, flags);
                 }                
             }
         }
--- a/qt/d1/qt/QtdObject.d	Wed Sep 16 14:16:33 2009 +0000
+++ b/qt/d1/qt/QtdObject.d	Thu Sep 17 16:28:41 2009 +0000
@@ -273,7 +273,7 @@
     {
         debug(QtdVerbose) __print("In QtdObject destructor");
         
-        if (__prev || __root is this)
+        if (__prev || __root is this)d
             __unpin;
     }    
 }