changeset 292:19498f420252 signals

more QList goodness
author eldar
date Tue, 10 Nov 2009 19:29:42 +0000
parents 0d2094800bdb
children 8627891e4556
files build/core.txt cpp/qt_core/QMetaObject_shell.cpp generator/cppimplgenerator.cpp generator/cppimplgenerator.h generator/dgenerator.cpp generator/dgenerator.h qt/QGlobal.d qt/core/QList.d qt/core/QTypeInfo.d qt/qtd/MOC.d qt/qtd/MetaMarshall.d
diffstat 11 files changed, 209 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/build/core.txt	Mon Nov 09 20:49:26 2009 +0000
+++ b/build/core.txt	Tue Nov 10 19:29:42 2009 +0000
@@ -18,7 +18,10 @@
     core/QString
     core/QMetaType
     core/QMetaObject
-
+    
+    core/QTypeInfo
+    core/QList
+    qtd/Atomic
     qtd/MetaMarshall
     qtd/MOC
     qtd/util/Tuple
@@ -57,4 +60,4 @@
     QBitArray
     QIODevice
     )
-    
+	
--- a/cpp/qt_core/QMetaObject_shell.cpp	Mon Nov 09 20:49:26 2009 +0000
+++ b/cpp/qt_core/QMetaObject_shell.cpp	Tue Nov 10 19:29:42 2009 +0000
@@ -1,6 +1,9 @@
 #include "qtd_core.h"
 #include <qobjectdefs.h>
 
+
+#include <QList>
+
 extern "C" DLL_PUBLIC void* qtd_QMetaObject_superClass(void *nativeId)
 {
     return (void*)((QMetaObject*)nativeId)->superClass();
@@ -37,3 +40,24 @@
 {
     return ((QMetaObject*)nativeId)->methodCount();
 }
+
+extern "C" DLL_PUBLIC void qtd_create_QList(void *nativeId)
+{
+    QList<int> & list = (*(QList<int> *)nativeId);
+    list.append(54);
+    list.append(45);
+}
+
+extern "C" DLL_PUBLIC void qtd_create_QList_QObject(void *nativeId)
+{
+    QList<QObject*> & list2 = (*(QList<QObject*> *)nativeId);
+    
+    QList<QObject*> list;
+    QObject* a1 = new QObject();
+    a1->setObjectName("a1");
+    list.append(a1);
+    QObject* a2 = new QObject();
+    a2->setObjectName("a2");
+    list.append(a2);
+    list2 = list;
+}
--- a/generator/cppimplgenerator.cpp	Mon Nov 09 20:49:26 2009 +0000
+++ b/generator/cppimplgenerator.cpp	Tue Nov 10 19:29:42 2009 +0000
@@ -710,6 +710,9 @@
 */
 // qtd    writeJavaLangObjectOverrideFunctions(s, java_class);
 
+    if (java_class->typeEntry()->isValue())
+        writeValueFunctions(s, java_class);
+
     if (java_class->isQObject())
     {
         s << endl << endl
@@ -723,6 +726,15 @@
     priGenerator->addSource(java_class->package(), fileNameForClass(java_class));
 }
 
+void CppImplGenerator::writeValueFunctions(QTextStream &s, const AbstractMetaClass *java_class)
+{
+    s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isComplex() { return (bool) QTypeInfo<%1>::isComplex; }\n").arg(java_class->name());
+    s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isStatic() { return (bool) QTypeInfo<%1>::isStatic; }\n").arg(java_class->name());
+    s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isLarge() { return (bool) QTypeInfo<%1>::isLarge; }\n").arg(java_class->name());
+    s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isPointer() { return (bool) QTypeInfo<%1>::isPointer; }\n").arg(java_class->name());
+    s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isDummy() { return (bool) QTypeInfo<%1>::isDummy; }\n").arg(java_class->name());
+}
+
 void CppImplGenerator::writeVirtualDispatchFunction(QTextStream &s, const AbstractMetaFunction *function, bool d_export)
 {
             uint options2 = ReturnType | ExternC;
--- a/generator/cppimplgenerator.h	Mon Nov 09 20:49:26 2009 +0000
+++ b/generator/cppimplgenerator.h	Tue Nov 10 19:29:42 2009 +0000
@@ -215,6 +215,7 @@
     static void writeInitCallbacks(QTextStream &s, const AbstractMetaClass *java_class);
     static void writeQtdEntityFunction(QTextStream &s, const AbstractMetaClass *java_class);
     void writeRefArguments(QTextStream &s, const AbstractMetaFunction *java_function);
+    void writeValueFunctions(QTextStream &s, const AbstractMetaClass *java_class);
 
 private:
     void writeDefaultConstructedValues_helper(QSet<QString> &values,
--- a/generator/dgenerator.cpp	Mon Nov 09 20:49:26 2009 +0000
+++ b/generator/dgenerator.cpp	Tue Nov 10 19:29:42 2009 +0000
@@ -1820,7 +1820,7 @@
     auxFile.isDone = true;
     auxFile.stream << "module " << auxModName << ";" << endl << endl;
 
-    bool staticInit = d_class->isQObject() || (cpp_shared && d_class->generateShellClass() && !d_class->isInterface());
+    bool staticInit = d_class->isQObject() || d_class->typeEntry()->isValue() || (cpp_shared && d_class->generateShellClass() && !d_class->isInterface());
     if (staticInit)
     {
         auxFile.isDone = false;
@@ -2261,13 +2261,15 @@
     if (d_class->baseClassName().isEmpty())
     {
         if (d_class->typeEntry()->isQObject())
-            s << INDENT << "public static enum __isQObjectType = true;" << endl << endl;
+            s << INDENT << "public alias void __isQObjectType;" << endl << endl;
         else if (d_class->typeEntry()->isObject())
-            s << INDENT << "public static enum __isObjectType = true;" << endl << endl;
+            s << INDENT << "public alias void __isObjectType;" << endl << endl;
         else if (d_class->typeEntry()->isValue())
-            s << INDENT << "public static enum __isValueType = true;" << endl << endl;
+            s << INDENT << "public alias void __isValueType;" << endl << endl;
     }
 
+    s << INDENT << "public alias void __isQtType_" << d_class->name() << ";" << endl << endl;
+
     // Add dummy constructor for use when constructing subclasses
     if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) {
         s << endl
@@ -2377,6 +2379,8 @@
         writeDestructor(s, d_class);
     }
 
+    if (d_class->typeEntry()->isValue())
+        writeValueFunctions(s, d_class);
 /* qtd
     // Add a function that converts an array of the value type to a QNativePointer
     if (d_class->typeEntry()->isValue() && !fakeClass) {
@@ -2412,7 +2416,7 @@
         writeCloneFunction(s, d_class);
     }
 */
-    s << "}" << endl;
+    s << "}" << endl; // end of class scope
 
     /* ---------------- injected free code ----------------*/ 
     const ComplexTypeEntry *class_type = d_class->typeEntry(); 
@@ -2602,6 +2606,9 @@
 
         s << "extern(C) void static_init_" << d_class->name() << "() {" << endl;
 
+        if (d_class->typeEntry()->isValue())
+            s << INDENT << d_class->name() << ".QTypeInfo.init();" << endl;
+
         if (d_class->isQObject()) {
             s << INDENT << "if (!" << d_class->name() << "._staticMetaObject) " << endl
             << INDENT << "    " << d_class->name() << ".createStaticMetaObject;" << endl << endl;
@@ -2659,6 +2666,38 @@
 
     if (d_class->isQObject())
         writeQObjectFreeFunctions(s, d_class);
+
+    if (d_class->typeEntry()->isValue())
+        writeValueFreeFunctions(s, d_class);
+}
+
+void DGenerator::writeValueFunctions(QTextStream &s, const AbstractMetaClass *d_class)
+{
+    s << INDENT << "struct QTypeInfo {" << endl;
+    s << INDENT << "    static __gshared bool isComplex;" << endl;
+    s << INDENT << "    static __gshared bool isStatic;" << endl;
+    s << INDENT << "    static __gshared bool isLarge;" << endl;
+    s << INDENT << "    static __gshared bool isPointer;" << endl;
+    s << INDENT << "    static __gshared bool isDummy;" << endl << endl;
+
+    s << INDENT << "    static init() {" << endl;
+
+    s <<   QString("        isComplex = qtd_%1_QTypeInfo_isComplex();\n"
+                   "        isStatic = qtd_%1_QTypeInfo_isStatic();\n"
+                   "        isLarge = qtd_%1_QTypeInfo_isLarge();\n"
+                   "        isPointer = qtd_%1_QTypeInfo_isPointer();\n"
+                   "        isDummy = qtd_%1_QTypeInfo_isDummy();\n").arg(d_class->name())
+                << "        }" << endl
+                << "    }" << endl << endl;
+}
+
+void DGenerator::writeValueFreeFunctions(QTextStream &s, const AbstractMetaClass *d_class)
+{
+    s << QString("private extern (C) bool qtd_%1_QTypeInfo_isComplex();\n").arg(d_class->name());
+    s << QString("private extern (C) bool qtd_%1_QTypeInfo_isStatic();\n").arg(d_class->name());
+    s << QString("private extern (C) bool qtd_%1_QTypeInfo_isLarge();\n").arg(d_class->name());
+    s << QString("private extern (C) bool qtd_%1_QTypeInfo_isPointer();\n").arg(d_class->name());
+    s << QString("private extern (C) bool qtd_%1_QTypeInfo_isDummy();\n").arg(d_class->name());
 }
 
 void DGenerator::writeConversionFunction(QTextStream &s, const AbstractMetaClass *d_class)
--- a/generator/dgenerator.h	Mon Nov 09 20:49:26 2009 +0000
+++ b/generator/dgenerator.h	Tue Nov 10 19:29:42 2009 +0000
@@ -160,6 +160,8 @@
     void writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class);
     void writeQObjectFreeFunctions(QTextStream &s, const AbstractMetaClass *d_class);
     void writeConversionFunction(QTextStream &s, const AbstractMetaClass *d_class);
+    void writeValueFreeFunctions(QTextStream &s, const AbstractMetaClass *d_class);
+    void writeValueFunctions(QTextStream &s, const AbstractMetaClass *d_class);
 
 //    void writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class);
 
--- a/qt/QGlobal.d	Mon Nov 09 20:49:26 2009 +0000
+++ b/qt/QGlobal.d	Tue Nov 10 19:29:42 2009 +0000
@@ -365,7 +365,7 @@
 /*
   The catch-all template.
 */
-
+/*
 bool qIsDetached(T)(T) { return true; }
 
 class QTypeInfossss(T)
@@ -391,7 +391,7 @@
         isDummy = false
     };
 };
-
+*/
 
 /*
    Specialize a specific type with:
--- a/qt/core/QList.d	Mon Nov 09 20:49:26 2009 +0000
+++ b/qt/core/QList.d	Tue Nov 10 19:29:42 2009 +0000
@@ -2,12 +2,36 @@
 
 import qt.QGlobal;
 import qt.qtd.Atomic;
+//import qt.core.QTypeInfo;
+
+import qt.qtd.MetaMarshall;
 
 import core.stdc.stdlib : qRealloc = realloc, qFree = free, qMalloc = malloc;
 import core.stdc.string : memcpy, memmove;
 
+import std.traits;
+
 enum INT_MAX = int.max;
 
+bool isComplex(T)()
+    if (is(typeof(T.QTypeInfo)))
+{
+    return T.QTypeInfo.isComplex();
+}
+
+bool isStatic(T)()
+    if (is(typeof(T.QTypeInfo)))
+{
+    return T.QTypeInfo.isStatic();
+}
+
+bool isLarge(T)()
+    if (is(typeof(T.QTypeInfo)))
+{
+    return T.QTypeInfo.isLarge();
+}
+
+
 int qAllocMore(int alloc, int extra)
 {
     if (alloc == 0 && extra == 0)
@@ -34,10 +58,10 @@
 private int grow(int size)
 {
     // dear compiler: don't optimize me out.
-    synchronized {
+//    synchronized {
         int x = qAllocMore(size * (void*).sizeof, QListData.DataHeaderSize) / (void*).sizeof;
         return x;
-    }
+//    }
 }
 
 struct QListData {
@@ -271,11 +295,23 @@
     struct Node
     {
         void *v;
-    
-        ref T t()
-        { return *cast(T*)(&this); }
-//        { return *cast(T*)(QTypeInfo!T.isLarge || QTypeInfo!T.isStatic
-//                                       ? v : &this); }    }
+        
+        static if (isQObjectType!T)
+        {
+            T t()
+            {
+                return T.__getObject( *cast(void**)(&this) );
+            }
+        }
+        else
+        {    
+            ref T t()
+            {
+                return *cast(T*)(&this);
+            }
+    //        { return *cast(T*)(QTypeInfo!T.isLarge || QTypeInfo!T.isStatic
+    //                                       ? v : &this); }    }
+        }
     }
     
     union {
@@ -329,6 +365,9 @@
         return this;
     }
     
+    int length() const { return p.size(); }
+    int size() const { return length; }
+
     void detach() { if (d.ref_.load() != 1) detach_helper(); }
     
     private void detach_helper()
@@ -347,28 +386,47 @@
         {
             node_construct(cast(Node*)(p.append()), t);
         }
-        else*/
+        else*/ static if (isQObjectType!T)
+        {
+            auto n = cast(Node*)(p.append());
+            *cast(void**)(n) = cast(Node*) t.__nativeId;
+        }
+        else
         {
             const T cpy = t;
             node_construct(cast(Node*)(p.append()), cpy);
         }
     }
+
+    static if (isQObjectType!T)
+    {
+        T at(int i) const
+        {
+            assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range");
+            return (cast(Node*)(p.at(i))).t();
+        }
+    }
+    else
+    {
+        ref const (T) at(int i) const
+        {
+            assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range");
+            return (cast(Node*)(p.at(i))).t();
+        }
+    }   
     
-    ref const (T) at(int i) const
-    {
-        assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range");
-        return (cast(Node*)(p.at(i))).t();
-    }
-
-    void node_construct(Node *n, const ref T t)
-    {
-/* TODO       static if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic)
-            n.v = new T(t);
-        else static if (QTypeInfo!T.isComplex)
-            new (n) T(t);
-        else*/
-            *cast(T*)(n) = t;
-    }
+    static if (isQObjectType!T)
+        { }
+    else
+        void node_construct(Node *n, const ref T t)
+        {
+    /* TODO       static if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic)
+                n.v = new T(t);
+            else static if (QTypeInfo!T.isComplex)
+                new (n) T(t);
+            else*/
+                { *cast(T*)(n) = cast(T)(t); }
+        }
     
     void node_copy(Node *from, Node *to, Node *src)
     {
@@ -383,6 +441,7 @@
 
     void free(QListData.Data* data)
     {
+        writeln("QList data destroyed");
         node_destruct(cast(Node*)(data.array.ptr + data.begin),
                       cast(Node*)(data.array.ptr + data.end));
         if (data.ref_.load() == 0)
@@ -400,3 +459,4 @@
 }
 
 extern(C) void qtd_create_QList(void *nativeId);
+extern(C) void qtd_create_QList_QObject(void *nativeId);
\ No newline at end of file
--- a/qt/core/QTypeInfo.d	Mon Nov 09 20:49:26 2009 +0000
+++ b/qt/core/QTypeInfo.d	Tue Nov 10 19:29:42 2009 +0000
@@ -6,22 +6,27 @@
 /*
   The catch-all template.
 */
+import std.traits;
+
+import qt.qtd.MetaMarshall;
 
 bool qIsDetached(T)(ref T) { return true; }
 
-struct QTypeInfo(T)
+template QTypeInfo(T)
+    if ( !(isQObjectType!T || isObjectType!T) )
 {
 public:
     enum {
-        isPointer = false,
-        isComplex = true,
-        isStatic = true,
-        isLarge = (T.sizeof > sizeof(void*)),
+        isPointer = isPointer!T,
+        isComplex = !isPointer,
+        isStatic = !isPointer,
+        isLarge = (T.sizeof > (void*).sizeof),
         isDummy = false
     }
 }
 
-struct QTypeInfo(T : T*)
+template QTypeInfo(T)
+    if ( isQObjectType!T || isObjectType!T )
 {
 public:
     enum {
@@ -33,27 +38,6 @@
     }
 }
 
-#else
-
-template <typename T> char QTypeInfoHelper(T*(*)());
-void* QTypeInfoHelper(...);
-
-template <typename T> inline bool qIsDetached(T &) { return true; }
-
-template <typename T>
-class QTypeInfo
-{
-public:
-    enum {
-        isPointer = (1 == sizeof(QTypeInfoHelper((T(*)())0))),
-        isComplex = !isPointer,
-        isStatic = !isPointer,
-        isLarge = (sizeof(T)>sizeof(void*)),
-        isDummy = false
-    };
-};
-
-#endif /* QT_NO_PARTIAL_TEMPLATE_SPECIALIZATION */
 
 /*
    Specialize a specific type with:
@@ -63,29 +47,33 @@
    where 'type' is the name of the type to specialize and 'flags' is
    logically-OR'ed combination of the flags below.
 */
-enum { /* TYPEINFO flags */
+
+/* presents in QGlobal
+enum { /* TYPEINFO flags
     Q_COMPLEX_TYPE = 0,
     Q_PRIMITIVE_TYPE = 0x1,
     Q_STATIC_TYPE = 0,
     Q_MOVABLE_TYPE = 0x2,
     Q_DUMMY_TYPE = 0x4
-};
+}
+*/
 
-#define Q_DECLARE_TYPEINFO(TYPE, FLAGS) \
-template <> \
-class QTypeInfo<TYPE> \
-{ \
-public: \
-    enum { \
-        isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \
-        isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \
-        isLarge = (sizeof(TYPE)>sizeof(void*)), \
-        isPointer = false, \
-        isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0) \
-    }; \
-    static inline const char *name() { return #TYPE; } \
+/*
+template QTypeInfo(alias FLAGS)
+{
+    template QTypeInfo(TYPE)
+    {
+    public:
+        enum {
+            isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0),
+            isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0),
+            isLarge = (TYPE.sizeof > (void*).sizeof),
+            isPointer = false,
+            isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0)
+        }
+    }
 }
-
+*/
 /*
    Specialize a shared type with:
 
@@ -95,6 +83,7 @@
    types must declare a 'bool isDetached(void) const;' member for this
    to work.
 */
+/*
 #if defined Q_CC_MSVC && _MSC_VER < 1300
 template <typename T>
 inline void qSwap_helper(T &value1, T &value2, T*)
@@ -122,3 +111,4 @@
     value2.data_ptr() = t; \
 }
 #endif
+*/
\ No newline at end of file
--- a/qt/qtd/MOC.d	Mon Nov 09 20:49:26 2009 +0000
+++ b/qt/qtd/MOC.d	Tue Nov 10 19:29:42 2009 +0000
@@ -529,6 +529,6 @@
     
     alias TupleWrapper!(findSymbols!(slotPrefix,   typeof(this), ByOwner!(typeof(this)))) Slots;
     alias TupleWrapper!(findSymbols!(signalPrefix, typeof(this), ByOwner!(typeof(this)))) Signals;
-//    pragma(msg, generateMetaInfo!((typeof(this)).stringof, Signals, Slots)());
+    pragma(msg, generateMetaInfo!((typeof(this)).stringof, Signals, Slots)());
     mixin(generateMetaInfo!((typeof(this)).stringof, Signals, Slots)());
 }
--- a/qt/qtd/MetaMarshall.d	Mon Nov 09 20:49:26 2009 +0000
+++ b/qt/qtd/MetaMarshall.d	Tue Nov 10 19:29:42 2009 +0000
@@ -4,12 +4,12 @@
 
 template isQObjectType(T) // is a QObject type that belongs to the library
 {
-    enum isQObjectType = is(typeof(mixin("T." ~ "__isQObjectType")));
+    enum isQObjectType = is(T.__isQObjectType);
 }
 
 template isObjectType(T) // is a QObject type that belongs to the library
 {
-    enum isQObjectType = is(typeof(mixin("T." ~ "__isObjectType")));
+    enum isObjectType = is(T.__isObjectType);
 }
 
 template isValueType(T) // is a QObject type that belongs to the library