changeset 167:ae06da58ec25

fixed hacky conversion of arguments when emmitting a signal
author eldar
date Sat, 20 Jun 2009 19:14:29 +0000
parents 52da31f967f0
children d66bbb9a5053
files Makefile build/core.makefile build/core.txt build/gui.makefile build/gui.txt generator/containergenerator.cpp generator/containergenerator.h generator/cppimplgenerator.cpp generator/dgenerator.cpp generator/dgenerator.h generator/generator.h generator/generatorsetd.cpp generator/qtjambi_masterinclude.h qt/QGlobal.d
diffstat 14 files changed, 138 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Jun 18 16:09:18 2009 +0000
+++ b/Makefile	Sat Jun 20 19:14:29 2009 +0000
@@ -56,7 +56,7 @@
 NAME_PREFIX = qtd
 endif
 ifndef $(PACKAGES)
-PACKAGES = core gui
+PACKAGES = core network
 endif
 LIB_PREFIX = lib
 CC_INCLUDE += include $(QTDIR_INC) $(QTDIR_INC)$(SL)Qt $(QTDIR_INC)$(SL)QtCore $(QTDIR_INC)$(SL)QtGui $(QTDIR_INC)$(SL)QtOpenGL $(QTDIR_INC)$(SL)QtSvg
@@ -151,7 +151,7 @@
 	cd generator && qmake && $(MAKE)
 
 dgen:  make_gen
-	cd generator && $(GEN) $(GEN_OPT) --d-target=$(D_TARGET) --output-directory=../ qtjambi_masterinclude.h build_gui.txt
+	cd generator && $(GEN) $(GEN_OPT) --d-target=$(D_TARGET) --output-directory=../ qtjambi_masterinclude.h build_network.txt
 ## DGenerator ## end
 
 mkdir:
--- a/build/core.makefile	Thu Jun 18 16:09:18 2009 +0000
+++ b/build/core.makefile	Sat Jun 20 19:14:29 2009 +0000
@@ -21,7 +21,7 @@
 core_cpp_files += cpp/qt_qtd/qtd_core.cpp cpp/qt_qtd/ArrayOpsPrimitive_shell.cpp
 
 ## Module specific d files.
-core_d_files += $(QTD_CORE:%=qt/%.d)
+core_d_files += $(QTD_CORE:%=qt/%.d) qt/core/ArrayOps2
 
 ## Classes.
 ## TODO: use list that genareted by dgen.
--- a/build/core.txt	Thu Jun 18 16:09:18 2009 +0000
+++ b/build/core.txt	Sat Jun 20 19:14:29 2009 +0000
@@ -8,6 +8,7 @@
     qt_core/QModelIndex_shell qt_core/QMetaType_shell)
 ## Module specific d files.
 set (d_files qtd/Array qtd/Str QtDObject qtd/ArrayOpsPrimitive
+    core/ArrayOps2
     core/QPoint core/QPointF
     core/QSize core/QSizeF
     core/QLine core/QLineF
--- a/build/gui.makefile	Thu Jun 18 16:09:18 2009 +0000
+++ b/build/gui.makefile	Sat Jun 20 19:14:29 2009 +0000
@@ -11,7 +11,7 @@
 gui_cpp_files += 
 
 ## Module specific d files.
-gui_d_files += 
+gui_d_files += qt/gui/ArrayOps2
 
 ## Classes.
 ## TODO: use list that generated by dgen.
--- a/build/gui.txt	Thu Jun 18 16:09:18 2009 +0000
+++ b/build/gui.txt	Sat Jun 20 19:14:29 2009 +0000
@@ -1,6 +1,6 @@
 set(required Core)
 set (cpp_files qt_gui/UrlHandler_shell)
-set (d_files gui/UrlHandler)
+set (d_files gui/UrlHandler gui/ArrayOps2)
 set(classes
     QPushButton
     QFileIconProvider
--- a/generator/containergenerator.cpp	Thu Jun 18 16:09:18 2009 +0000
+++ b/generator/containergenerator.cpp	Sat Jun 20 19:14:29 2009 +0000
@@ -45,8 +45,8 @@
 
 static Indentor INDENT;
 
-ContainerGenerator::ContainerGenerator():
-        DGenerator()
+ContainerGenerator::ContainerGenerator(CppImplGenerator *cpp_impl_generator):
+        DGenerator(), m_cpp_impl_generator(cpp_impl_generator)
 
 {
     setFilenameStub("ArrayOps");
@@ -133,6 +133,7 @@
 
             processFunction(function);
         }
+
         AbstractMetaFieldList fields = d_class->fields();
         foreach (const AbstractMetaField *field, fields) {
             if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal())) {
@@ -141,6 +142,27 @@
             }
         }
 
+        AbstractMetaFunctionList signal_funcs = signalFunctions(d_class);
+        for(int i = 0; i < signal_funcs.size(); i++) {
+            AbstractMetaFunction *signal = signal_funcs.at(i);
+
+            AbstractMetaArgumentList arguments = signal->arguments();
+            foreach (AbstractMetaArgument *argument, arguments) {
+                if(argument->type()->isContainer()) {
+                    bool inList = false;
+                    foreach(AbstractMetaType* type, signalEntries[d_class->package()]) {
+                        const TypeEntry *teInList = type->instantiations().first()->typeEntry();
+                        const TypeEntry *te = argument->type()->instantiations().first()->typeEntry();
+
+                        if ((te == teInList) && (argument->type()->typeEntry() == type->typeEntry()))
+                            inList = true;
+                    }
+                    if (!inList)
+                        (signalEntries[d_class->package()]) << argument->type();
+//                    (signalEntries[d_class->package()])[argument->type()->instantiations().first()->typeEntry()] = argument->type();
+                }
+            }
+        }
     }
 }
 
@@ -151,6 +173,7 @@
     writeFile(cppFilename(), CppDirectory, &ContainerGenerator::writeCppContent); // cpp file
     writeFile("ArrayOps_%1.h", HDirectory, &ContainerGenerator::writeHeaderContent); // header file
     writeFile(dFilename(), DDirectory, &ContainerGenerator::writeDContent); // d file
+    writeFile("ArrayOps2.d", DDirectory, &ContainerGenerator::writeDContent2); // d file
 }
 
 void ContainerGenerator::writeFile(const QString& fileName, OutputDirectoryType dirType, WriteOut writeOut)
@@ -193,8 +216,13 @@
     QString package = cls->package().replace(".", "_");
 
     s << "// stuff for passing D function pointers" << endl << endl
-      << "#ifdef CPP_SHARED" << endl << endl
-      << "#include \"ArrayOps_" << package << ".h\"" << endl << endl;
+      << "#include \"qtd_masterinclude.h\"" << endl << endl
+      << "#include \"qtd_core.h\"" << endl
+      << "#include \"ArrayOps_" << package << ".h\"" << endl
+      << "#include \"ArrayOps_qt_core.h\"" << endl
+      << "#include \"ArrayOpsPrimitive.h\"" << endl << endl
+      << "#ifdef CPP_SHARED" << endl << endl;
+
 
     foreach (const TypeEntry *te, containerTypes) {
         if (te->javaPackage() == cls->package()) {
@@ -228,6 +256,38 @@
     }
     s << "}" << endl
       << "#endif" << endl;
+/*
+    QMap<const TypeEntry*, AbstractMetaType*> typeList = signalEntries[cls->package()];
+
+    QMapIterator<const TypeEntry*, AbstractMetaType*> i(typeList);
+    while (i.hasNext()) {
+        i.next();
+        s << "// " << i.key()->targetLangName() << endl
+          << "extern \"C\" DLL_PUBLIC void qtd_" << package << "_" << i.key()->targetLangName() << "_to_d_array(void *cpp_ptr, DArray* __d_container) {" << endl;
+
+        AbstractMetaType *arg_type = i.value();
+        m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption);
+        s << "container = (*reinterpret_cast< ";
+        m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference);
+        s << "(*)>(cpp_ptr));" << endl;
+
+        m_cpp_impl_generator->writeQtToJavaContainer(s, arg_type, "container", "__d_container", 0, -1);
+        s << "}" << endl;
+    }*/
+
+    foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) {
+        const TypeEntry *te = arg_type->instantiations().first()->typeEntry();
+        s << "// " << te->targetLangName() << endl
+          << "extern \"C\" DLL_PUBLIC void " << fromCppContainerName(cls, arg_type) << "(void *cpp_ptr, DArray* __d_container) {" << endl;
+
+        m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption);
+        s << "container = (*reinterpret_cast< ";
+        m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference);
+        s << "(*)>(cpp_ptr));" << endl;
+
+        m_cpp_impl_generator->writeQtToJavaContainer(s, arg_type, "container", "__d_container", 0, -1);
+        s << "}" << endl;
+    }
 }
 
 void ContainerGenerator::writeHeaderContent(QTextStream &s, AbstractMetaClass *cls)
@@ -334,6 +394,20 @@
     s << "        qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(callbacks.ptr);" << endl
       << "    }" << endl
       << "}" << endl;
+
+
+}
+
+void ContainerGenerator::writeDContent2(QTextStream &s, AbstractMetaClass *cls)
+{
+    s << "module " << cls->package() << ".ArrayOps2;" << endl << endl;
+
+    foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) {
+        const TypeEntry *te = arg_type->instantiations().first()->typeEntry();
+        if(!te->isPrimitive() && !te->isString())
+            writeImportString(s, te);
+        s << "extern (C) void " << fromCppContainerName(cls, arg_type) << "(void *cpp_ptr, " << te->targetLangName() << "[]* __d_container);" << endl;
+    }
 }
 
 void ContainerGenerator::writeNotice(QTextStream &s)
--- a/generator/containergenerator.h	Thu Jun 18 16:09:18 2009 +0000
+++ b/generator/containergenerator.h	Sat Jun 20 19:14:29 2009 +0000
@@ -61,7 +61,7 @@
 
     typedef void (ContainerGenerator::*WriteOut)(QTextStream &s, AbstractMetaClass *cls);
 
-    ContainerGenerator();
+    ContainerGenerator(CppImplGenerator *cpp_impl_generator);
 
     virtual void generate();
     virtual void write(QTextStream &s, const AbstractMetaClass *java_class);
@@ -71,6 +71,7 @@
     void writeHeaderContent(QTextStream &s, AbstractMetaClass *cls);
     void writeCppContent(QTextStream &s, AbstractMetaClass *cls);
     void writeDContent(QTextStream &s, AbstractMetaClass *cls);
+    void writeDContent2(QTextStream &s, AbstractMetaClass *cls);
 
     void buildTypeList();
 
@@ -100,6 +101,10 @@
     AbstractMetaClass* m_class;
 
     QString all_name, ass_name, get_name;
+//    QMap<QString, QMap<const TypeEntry*, AbstractMetaType*> > signalEntries;
+    QMap<QString, QSet<AbstractMetaType*> > signalEntries;
+
+    CppImplGenerator *m_cpp_impl_generator;
 };
 
 #endif // CONTAINERGENERATOR_H
--- a/generator/cppimplgenerator.cpp	Thu Jun 18 16:09:18 2009 +0000
+++ b/generator/cppimplgenerator.cpp	Sat Jun 20 19:14:29 2009 +0000
@@ -1382,7 +1382,7 @@
         // D-side signal callbacks
         for(int i = 0; i < signal_funcs.size(); i++) {
             AbstractMetaFunction *signal = signal_funcs.at(i);
-            writeSignalHandler(s, java_class, signal);
+            s << "extern \"C\" DLL_PUBLIC void " << signalExternName(java_class, signal) << "_handle(void* d_entity, void** args);" << endl;
         }
 
 	if(signal_funcs.size() > 0)
@@ -3239,7 +3239,7 @@
         cls_name.remove("_ConcreteWrapper");
 
         s << endl
-          << INDENT << "{" << endl // qtd2 hack, additional scope for avoiding duplicating of "i"
+//          << INDENT << "{" << endl // qtd2 hack, additional scope for avoiding duplicating of "i"
           << INDENT;
 
         switch (type->type()) {
@@ -3264,8 +3264,9 @@
 
 
         writeTypeInfo(s, java_type, ForceValueType);
+        QString index = "i_" + qt_name;
         s << "::const_iterator " << qt_name << "_end_it = " << qt_name << ".constEnd();" << endl
-          << INDENT << "int i = 0;" << endl
+          << INDENT << QString("int %0 = 0;").arg(index) << endl
           << INDENT;
         s << "for (";
         writeTypeInfo(s, java_type, ForceValueType);
@@ -3278,15 +3279,15 @@
             s << " __qt_tmp = *" << qt_name << "_it;" << endl;
 
             if(targ->isTargetLangString())
-                s << INDENT << "void *__java_tmp = qtd_string_from_array(" << java_name << ", i);" << endl;
+                s << INDENT << "void *__java_tmp = qtd_string_from_array(" << java_name << ", " << index << ");" << endl;
 
             writeQtToJava(s, targ, "__qt_tmp", "__java_tmp", 0, -1, BoxedPrimitive);
 
-            s << INDENT << "qtd_assign_" << cls_name << "_array_element(" << java_name << ", i, __java_tmp);" << endl;
-            s << INDENT << "++i;" << endl;
+            s << INDENT << "qtd_assign_" << cls_name << "_array_element(" << java_name << ", " << index << ", __java_tmp);" << endl;
+            s << INDENT << "++" << index << ";" << endl;
         }
-        s << INDENT << "}" << endl
-          << INDENT << "}" << endl;
+        s << INDENT << "}" << endl;
+//          << INDENT << "}" << endl;
 
     } else if (type->type() == ContainerTypeEntry::PairContainer) {
         QList<AbstractMetaType *> args = java_type->instantiations();
--- a/generator/dgenerator.cpp	Thu Jun 18 16:09:18 2009 +0000
+++ b/generator/dgenerator.cpp	Sat Jun 20 19:14:29 2009 +0000
@@ -43,7 +43,6 @@
 #include "reporthandler.h"
 #include "docparser.h"
 #include "jumptable.h"
-#include "cppimplgenerator.h"
 #include "fileout.h"
 
 #include <QtCore/QDir>
@@ -1717,10 +1716,9 @@
 
         s << "private " << attr << "extern(C) void " << sigExternName << "_connect(void* native_id);" << endl;
         s << "private " << attr << "extern(C) void " << sigExternName << "_disconnect(void* native_id);" << endl;
-
+/*
         QString extra_args;
 
-        AbstractMetaArgumentList arguments = signal->arguments();
         foreach (AbstractMetaArgument *argument, arguments) {
             if(argument->type()->isContainer()) {
                 QString arg_name = argument->indexedName();
@@ -1729,8 +1727,10 @@
                 extra_args += ", " + type_string + " " + arg_name;
             }
         }
-
-        s << "private extern(C) void " << sigExternName << "_handle_in_d(void* d_entity, void** args" << extra_args<< ") {" << endl;
+*/
+        AbstractMetaArgumentList arguments = signal->arguments();
+
+        s << "private extern(C) void " << sigExternName << "_handle(void* d_entity, void** args) {" << endl;
         {
             Indentation indent(INDENT);
             s << INDENT << "auto d_object = cast(" << d_class->name() << ") d_entity;" << endl;
@@ -1744,10 +1744,13 @@
 
                 QString arg_ptr = QString("args[%1]").arg(argument->argumentIndex() + 1);
 
-                if (type->isTargetLangString())
+                if (type->isContainer()) {
+                    s << INDENT << translateType(type, signal->implementingClass(), BoxedPrimitive) << " " << arg_name << ";" << endl
+                      << INDENT << fromCppContainerName(d_class, type) << "(" << arg_ptr << ", &" << arg_name << ");" << endl;
+                } else if (type->isTargetLangString()) {
                     s << INDENT << "auto " << arg_name << "_ptr = " << arg_ptr << ";" << endl
                       << INDENT << "string " << arg_name << " = QString.toNativeString(" << arg_name << "_ptr);";
-                else if(type->isPrimitive() || type->isEnum() || type->isFlags() || type->typeEntry()->isStructInD()) {
+                } else if(type->isPrimitive() || type->isEnum() || type->isFlags() || type->typeEntry()->isStructInD()) {
                     QString type_name = argument->type()->typeEntry()->qualifiedTargetLangName();
                     if (type->isFlags())
                         type_name = "int";
@@ -1755,14 +1758,14 @@
                 } else if(type->isObject() || type->isQObject()
                         || (type->typeEntry()->isValue() && type->isNativePointer())
                         || type->isValue()) {
-                        QString type_name = type->name();
-                        const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry());
-                        if(ctype->isAbstract())
-                            type_name = type_name + "_ConcreteWrapper";
-                        s << INDENT << "scope " << arg_name << " = new " << type_name
-                                    << "(cast(void*)(" << arg_ptr << "), true);" << endl
-                          << INDENT << arg_name << ".__no_real_delete = true;";
-                    }
+                    QString type_name = type->name();
+                    const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry());
+                    if(ctype->isAbstract())
+                        type_name = type_name + "_ConcreteWrapper";
+                    s << INDENT << "scope " << arg_name << " = new " << type_name
+                                << "(cast(void*)(" << arg_ptr << "), true);" << endl
+                                << INDENT << arg_name << ".__no_real_delete = true;";
+                }
                 s << endl;
             }
 //            s << INDENT << "Stdout(\"" << d_class->name() << "\", \"" << signal->name() << "\").newline;" << endl;
@@ -1886,6 +1889,8 @@
         else if (d_class->name() == "QApplication")
             s << "private import qt.gui.ArrayOps;" << endl;
 
+        s << "private import " << d_class->package() << ".ArrayOps2;" << endl;
+
         if (!d_class->enums().isEmpty())
             s << "public import " << d_class->package() << "." << d_class->name() << "_enum;" << endl << endl;
 
--- a/generator/dgenerator.h	Thu Jun 18 16:09:18 2009 +0000
+++ b/generator/dgenerator.h	Sat Jun 20 19:14:29 2009 +0000
@@ -44,6 +44,7 @@
 
 #include "generator.h"
 #include "metajava.h"
+#include "cppimplgenerator.h"
 
 #include <QTextStream>
 
--- a/generator/generator.h	Thu Jun 18 16:09:18 2009 +0000
+++ b/generator/generator.h	Sat Jun 20 19:14:29 2009 +0000
@@ -160,6 +160,14 @@
     return "qtd_" + cls->name() + "_" + signal->name();
 }
 
+inline QString fromCppContainerName(const AbstractMetaClass *cls, const AbstractMetaType *type)
+{
+    QString package = cls->package().replace(".", "_");
+    const TypeEntry *te = type->instantiations().first()->typeEntry();
+
+    return "qtd_" + package + "_" + te->targetLangName() + "_from_" + type->typeEntry()->qualifiedCppName();
+}
+
 bool notWrappedYet(const AbstractMetaFunction *java_function);
 bool isLinearContainer(const ContainerTypeEntry *type);
 AbstractMetaFunctionList signalFunctions(const AbstractMetaClass *cls);
--- a/generator/generatorsetd.cpp	Thu Jun 18 16:09:18 2009 +0000
+++ b/generator/generatorsetd.cpp	Sat Jun 20 19:14:29 2009 +0000
@@ -147,7 +147,7 @@
     // Code generation
     QList<Generator *> generators;
     PriGenerator *priGenerator = new PriGenerator;
-    ContainerGenerator *cointainerGenerator = new ContainerGenerator;
+    ContainerGenerator *cointainerGenerator;
     DGenerator *d_generator = 0;
     CppHeaderGenerator *cpp_header_generator = 0;
     CppImplGenerator *cpp_impl_generator = 0;
@@ -209,6 +209,9 @@
         contexts << "ClassListGenerator";
     }
 
+    cointainerGenerator = new ContainerGenerator(cpp_impl_generator);
+
+
     generators << priGenerator;
     contexts << "PriGenerator";
 
--- a/generator/qtjambi_masterinclude.h	Thu Jun 18 16:09:18 2009 +0000
+++ b/generator/qtjambi_masterinclude.h	Sat Jun 20 19:14:29 2009 +0000
@@ -59,13 +59,6 @@
 #  include <phonon/phonon>
 #endif
 
-#include <../qtjambi_designer/designer.h>
-
-#include <../qtjambi_gui/qtreemodel.h>
-#include <../qtjambi_gui/qguisignalmapper.h>
-
-#include <../qtjambi_core/qtjambiconcurrent.h>
-
 #ifndef QT_NO_OPENGL
 #define GL_ACCUM                          0x0100
 #define GL_LOAD                           0x0101
--- a/qt/QGlobal.d	Thu Jun 18 16:09:18 2009 +0000
+++ b/qt/QGlobal.d	Sat Jun 20 19:14:29 2009 +0000
@@ -401,9 +401,15 @@
 
 void qSwap(T)(ref T value1, ref T value2)
 {
+<<<<<<< .mine
+    const T.nativeId t = value1.nativeId;
+    value1.nativeId = value2.nativeId;
+    value2.nativeId = t;
+=======
     T t = value1;
     value1 = value2;
     value2 = t;
+>>>>>>> .r170
 }
 
 /*