changeset 152:4d1c5d1d1bbf

fix some inconsistencies with conversion functions
author eldar
date Mon, 15 Jun 2009 23:16:42 +0000
parents a28893622ff4
children ea0861a37bf6
files build/core.makefile build/core.txt generator/dgenerator.cpp
diffstat 3 files changed, 46 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/build/core.makefile	Mon Jun 15 15:40:21 2009 +0000
+++ b/build/core.makefile	Mon Jun 15 23:16:42 2009 +0000
@@ -74,4 +74,5 @@
     QProcess \
     QBuffer \
     QMetaType \
-    QLibraryInfo 
\ No newline at end of file
+    QLibraryInfo \
+    QXmlStreamEntityResolver
\ No newline at end of file
--- a/build/core.txt	Mon Jun 15 15:40:21 2009 +0000
+++ b/build/core.txt	Mon Jun 15 23:16:42 2009 +0000
@@ -55,5 +55,6 @@
     QProcess
     QBuffer
     QLibraryInfo
+    QXmlStreamEntityResolver
     )
 	
--- a/generator/dgenerator.cpp	Mon Jun 15 15:40:21 2009 +0000
+++ b/generator/dgenerator.cpp	Mon Jun 15 23:16:42 2009 +0000
@@ -2474,7 +2474,7 @@
         writeQObjectFunctions(s, d_class);
 
 
-    if (d_class->needsConversionFunc)
+//    if (d_class->needsConversionFunc)
         writeConversionFunction(s, d_class);
 
     if (d_class->hasConstructors())
@@ -2590,6 +2590,8 @@
 void DGenerator::writeConversionFunction(QTextStream &s, const AbstractMetaClass *d_class)
 {
     const ComplexTypeEntry *ctype = d_class->typeEntry();
+    if(!ctype->isQObject() && !ctype->isObject())
+        return;
     QString class_name = ctype->name();
     QString return_type_name = class_name;
     if(ctype->designatedInterface())
@@ -2614,88 +2616,12 @@
     } else if (ctype->isObject()) {
         QString type_name = class_name;
         if(ctype->isAbstract())
-            type_name = type_name + "_ConcreteWrapper";
+            type_name = ctype->targetLangName() + "_ConcreteWrapper";
 
         // if class has virtual functions then it has classname_entity function so
         // we can look for D Object pointer. otherwise create new wrapper
         if (d_class->hasVirtualFunctions()) {
-            s << INDENT << "void* d_obj = __" << ctype->name() << "_entity(__qt_return_value);" << endl
-              << INDENT << "if (d_obj !is null) {" << endl
-              << INDENT << "    auto d_obj_ref = cast (Object) d_obj;" << endl
-              << INDENT << "    return cast(" << return_type_name << ") d_obj_ref;" << endl
-              << INDENT << "} else {" << endl
-              << INDENT << "    auto return_value = new " << type_name << "(__qt_return_value, true);" << endl
-              << INDENT << "    return_value.__no_real_delete = true;" << endl
-              << INDENT << "    return return_value;" << endl
-              << INDENT << "}";
-        } else {
-            s << INDENT << "auto return_value = new " << type_name << "(__qt_return_value, true);" << endl
-              << INDENT << "return_value.__no_real_delete = true;" << endl
-              << INDENT << "return return_value;" << endl;
-        }
-    }
-    s << "}" << endl << endl;
-}
-
-
-void DGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class)
-{
-    s << "extern(C) void* qtd_" << d_class->name() << "_d_pointer(void *obj);" << endl
-      << "extern(C) void qtd_" << d_class->name() << "_create_link(void *obj, void* d_obj);" << endl << endl;
-    s << "private extern (C) void qtd_D_" << d_class->name() << "_delete(void *d_ptr) {" << endl
-      << "    auto d_ref = cast(QObject) d_ptr;" << endl
-      << "    d_ref.__no_real_delete = true;" << endl
-      << "    delete d_ref;" << endl
-      << "}" << endl << endl;
-}
-
-/*
-void DGenerator::writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class)
-{
-
-}
-*/
-void DGenerator::marshallFromCppToD(QTextStream &s, const ComplexTypeEntry* ctype)
-{
-    if(ctype->isQObject()) {
-        QString type_name = ctype->name();
-
-        if(ctype->isAbstract())
-            type_name = type_name + "_ConcreteWrapper";
-
-        s << INDENT << "if (__qt_return_value is null)" << endl
-                << INDENT << "    return null;" << endl
-                << INDENT << "void* d_obj = __QObject_entity(__qt_return_value);" << endl
-                << INDENT << "if (d_obj is null) {" << endl
-                << INDENT << "    auto new_obj = new " << type_name << "(__qt_return_value, true);" << endl
-                << INDENT << "    new_obj.__no_real_delete = true;" << endl
-                << INDENT << "    return new_obj;" << endl
-                << INDENT << "} else" << endl
-                << INDENT << "    return cast(" << ctype->name() << ") d_obj;" << endl;
-    } else if (ctype->isValue() && !ctype->isStructInD())
-        s << INDENT << "return new " << ctype->name() << "(__qt_return_value, false);" << endl;
-    else if (ctype->isVariant())
-        s << INDENT << "return new QVariant(__qt_return_value, false);" << endl;
-    else if (ctype->name() == "QModelIndex" || ctype->isStructInD())
-        s << INDENT << "return __qt_return_value;" << endl;
-    else if (ctype->isObject()) {
-        QString type_name = ctype->name();
-
-        if(ctype->isAbstract())
-            type_name = type_name + "_ConcreteWrapper";
-
-        QString return_type_name = ctype->name();
-        if(ctype->designatedInterface())
-            return_type_name = ctype->designatedInterface()->name();
-
-        AbstractMetaClass *d_class = NULL;
-        
-        d_class = ClassFromEntry::get(ctype);
-        
-        // if class has virtual functions then it has classname_entity function so
-        // we can look for D Object pointer. otherwise create new wrapper
-        if (d_class != NULL && d_class->hasVirtualFunctions()) {
-            s << INDENT << "void* d_obj = __" << ctype->name() << "_entity(__qt_return_value);" << endl
+            s << INDENT << "void* d_obj = __" << ctype->targetLangName() << "_entity(__qt_return_value);" << endl
               << INDENT << "if (d_obj !is null) {" << endl
               << INDENT << "    auto d_obj_ref = cast (Object) d_obj;" << endl
               << INDENT << "    return cast(" << return_type_name << ") d_obj_ref;" << endl
@@ -2710,7 +2636,42 @@
               << INDENT << "return return_value;" << endl;
         }
     }
-
+    s << "}" << endl << endl;
+}
+
+
+void DGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class)
+{
+    s << "extern(C) void* qtd_" << d_class->name() << "_d_pointer(void *obj);" << endl
+      << "extern(C) void qtd_" << d_class->name() << "_create_link(void *obj, void* d_obj);" << endl << endl;
+    s << "private extern (C) void qtd_D_" << d_class->name() << "_delete(void *d_ptr) {" << endl
+      << "    auto d_ref = cast(QObject) d_ptr;" << endl
+      << "    d_ref.__no_real_delete = true;" << endl
+      << "    delete d_ref;" << endl
+      << "}" << endl << endl;
+}
+
+/*
+void DGenerator::writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class)
+{
+
+}
+*/
+void DGenerator::marshallFromCppToD(QTextStream &s, const ComplexTypeEntry* ctype)
+{
+    if(ctype->isQObject()) {
+        QString type_name = ctype->name();
+        s << "return qtd_" << type_name << "_from_ptr(__qt_return_value);" << endl;
+    } else if (ctype->isValue() && !ctype->isStructInD()) {
+        s << INDENT << "return new " << ctype->name() << "(__qt_return_value, false);" << endl;
+    } else if (ctype->isVariant()) {
+        s << INDENT << "return new QVariant(__qt_return_value, false);" << endl;
+    } else if (ctype->name() == "QModelIndex" || ctype->isStructInD()) {
+        s << INDENT << "return __qt_return_value;" << endl;
+    } else if (ctype->isObject()) {
+        QString type_name = ctype->name();
+        s << "return qtd_" << type_name << "_from_ptr(__qt_return_value);" << endl;
+    }
 }
 
 void DGenerator::writeNativeField(QTextStream &s, const AbstractMetaField *field)
@@ -2989,7 +2950,7 @@
 
         foreach (AbstractMetaFunction *function, cls->functions())
             function->checkStoreResult();
-
+/* we don't need this anymore
         // generate QObject conversion functions only those that are required
         AbstractMetaFunctionList d_funcs = cls->functionsInTargetLang();
         for (int i=0; i<d_funcs.size(); ++i) {
@@ -3002,7 +2963,7 @@
                 if (d_class)
                     d_class->needsConversionFunc = true;
             }
-        }
+        }*/
     }
 
     Generator::generate();