Mercurial > projects > qtd
comparison generator/dgenerator.cpp @ 167:ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
author | eldar |
---|---|
date | Sat, 20 Jun 2009 19:14:29 +0000 |
parents | 4d1c5d1d1bbf |
children | d3f4f14d43a5 |
comparison
equal
deleted
inserted
replaced
166:52da31f967f0 | 167:ae06da58ec25 |
---|---|
41 | 41 |
42 #include "dgenerator.h" | 42 #include "dgenerator.h" |
43 #include "reporthandler.h" | 43 #include "reporthandler.h" |
44 #include "docparser.h" | 44 #include "docparser.h" |
45 #include "jumptable.h" | 45 #include "jumptable.h" |
46 #include "cppimplgenerator.h" | |
47 #include "fileout.h" | 46 #include "fileout.h" |
48 | 47 |
49 #include <QtCore/QDir> | 48 #include <QtCore/QDir> |
50 #include <QtCore/QTextStream> | 49 #include <QtCore/QTextStream> |
51 #include <QtCore/QVariant> | 50 #include <QtCore/QVariant> |
1715 foreach(AbstractMetaFunction *signal, signal_funcs) { | 1714 foreach(AbstractMetaFunction *signal, signal_funcs) { |
1716 QString sigExternName = signalExternName(d_class, signal); | 1715 QString sigExternName = signalExternName(d_class, signal); |
1717 | 1716 |
1718 s << "private " << attr << "extern(C) void " << sigExternName << "_connect(void* native_id);" << endl; | 1717 s << "private " << attr << "extern(C) void " << sigExternName << "_connect(void* native_id);" << endl; |
1719 s << "private " << attr << "extern(C) void " << sigExternName << "_disconnect(void* native_id);" << endl; | 1718 s << "private " << attr << "extern(C) void " << sigExternName << "_disconnect(void* native_id);" << endl; |
1720 | 1719 /* |
1721 QString extra_args; | 1720 QString extra_args; |
1722 | 1721 |
1723 AbstractMetaArgumentList arguments = signal->arguments(); | |
1724 foreach (AbstractMetaArgument *argument, arguments) { | 1722 foreach (AbstractMetaArgument *argument, arguments) { |
1725 if(argument->type()->isContainer()) { | 1723 if(argument->type()->isContainer()) { |
1726 QString arg_name = argument->indexedName(); | 1724 QString arg_name = argument->indexedName(); |
1727 const AbstractMetaType *arg_type = argument->type(); | 1725 const AbstractMetaType *arg_type = argument->type(); |
1728 QString type_string = translateType(argument->type(), signal->implementingClass(), BoxedPrimitive); | 1726 QString type_string = translateType(argument->type(), signal->implementingClass(), BoxedPrimitive); |
1729 extra_args += ", " + type_string + " " + arg_name; | 1727 extra_args += ", " + type_string + " " + arg_name; |
1730 } | 1728 } |
1731 } | 1729 } |
1732 | 1730 */ |
1733 s << "private extern(C) void " << sigExternName << "_handle_in_d(void* d_entity, void** args" << extra_args<< ") {" << endl; | 1731 AbstractMetaArgumentList arguments = signal->arguments(); |
1732 | |
1733 s << "private extern(C) void " << sigExternName << "_handle(void* d_entity, void** args) {" << endl; | |
1734 { | 1734 { |
1735 Indentation indent(INDENT); | 1735 Indentation indent(INDENT); |
1736 s << INDENT << "auto d_object = cast(" << d_class->name() << ") d_entity;" << endl; | 1736 s << INDENT << "auto d_object = cast(" << d_class->name() << ") d_entity;" << endl; |
1737 int sz = arguments.count(); | 1737 int sz = arguments.count(); |
1738 | 1738 |
1742 AbstractMetaType *type = argument->type(); | 1742 AbstractMetaType *type = argument->type(); |
1743 // if has QString argument we have to pass char* and str.length to QString constructor | 1743 // if has QString argument we have to pass char* and str.length to QString constructor |
1744 | 1744 |
1745 QString arg_ptr = QString("args[%1]").arg(argument->argumentIndex() + 1); | 1745 QString arg_ptr = QString("args[%1]").arg(argument->argumentIndex() + 1); |
1746 | 1746 |
1747 if (type->isTargetLangString()) | 1747 if (type->isContainer()) { |
1748 s << INDENT << translateType(type, signal->implementingClass(), BoxedPrimitive) << " " << arg_name << ";" << endl | |
1749 << INDENT << fromCppContainerName(d_class, type) << "(" << arg_ptr << ", &" << arg_name << ");" << endl; | |
1750 } else if (type->isTargetLangString()) { | |
1748 s << INDENT << "auto " << arg_name << "_ptr = " << arg_ptr << ";" << endl | 1751 s << INDENT << "auto " << arg_name << "_ptr = " << arg_ptr << ";" << endl |
1749 << INDENT << "string " << arg_name << " = QString.toNativeString(" << arg_name << "_ptr);"; | 1752 << INDENT << "string " << arg_name << " = QString.toNativeString(" << arg_name << "_ptr);"; |
1750 else if(type->isPrimitive() || type->isEnum() || type->isFlags() || type->typeEntry()->isStructInD()) { | 1753 } else if(type->isPrimitive() || type->isEnum() || type->isFlags() || type->typeEntry()->isStructInD()) { |
1751 QString type_name = argument->type()->typeEntry()->qualifiedTargetLangName(); | 1754 QString type_name = argument->type()->typeEntry()->qualifiedTargetLangName(); |
1752 if (type->isFlags()) | 1755 if (type->isFlags()) |
1753 type_name = "int"; | 1756 type_name = "int"; |
1754 s << INDENT << "auto " << arg_name << " = *(cast(" << type_name << "*)" << arg_ptr << ");"; | 1757 s << INDENT << "auto " << arg_name << " = *(cast(" << type_name << "*)" << arg_ptr << ");"; |
1755 } else if(type->isObject() || type->isQObject() | 1758 } else if(type->isObject() || type->isQObject() |
1756 || (type->typeEntry()->isValue() && type->isNativePointer()) | 1759 || (type->typeEntry()->isValue() && type->isNativePointer()) |
1757 || type->isValue()) { | 1760 || type->isValue()) { |
1758 QString type_name = type->name(); | 1761 QString type_name = type->name(); |
1759 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); | 1762 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); |
1760 if(ctype->isAbstract()) | 1763 if(ctype->isAbstract()) |
1761 type_name = type_name + "_ConcreteWrapper"; | 1764 type_name = type_name + "_ConcreteWrapper"; |
1762 s << INDENT << "scope " << arg_name << " = new " << type_name | 1765 s << INDENT << "scope " << arg_name << " = new " << type_name |
1763 << "(cast(void*)(" << arg_ptr << "), true);" << endl | 1766 << "(cast(void*)(" << arg_ptr << "), true);" << endl |
1764 << INDENT << arg_name << ".__no_real_delete = true;"; | 1767 << INDENT << arg_name << ".__no_real_delete = true;"; |
1765 } | 1768 } |
1766 s << endl; | 1769 s << endl; |
1767 } | 1770 } |
1768 // s << INDENT << "Stdout(\"" << d_class->name() << "\", \"" << signal->name() << "\").newline;" << endl; | 1771 // s << INDENT << "Stdout(\"" << d_class->name() << "\", \"" << signal->name() << "\").newline;" << endl; |
1769 s << INDENT << "d_object." << signal->name() << ".emit("; | 1772 s << INDENT << "d_object." << signal->name() << ".emit("; |
1770 for (int j = 0; j<sz; ++j) { | 1773 for (int j = 0; j<sz; ++j) { |
1883 // qtd2 hack! | 1886 // qtd2 hack! |
1884 if (d_class->name() == "QCoreApplication") | 1887 if (d_class->name() == "QCoreApplication") |
1885 s << "private import qt.core.ArrayOps;" << endl; | 1888 s << "private import qt.core.ArrayOps;" << endl; |
1886 else if (d_class->name() == "QApplication") | 1889 else if (d_class->name() == "QApplication") |
1887 s << "private import qt.gui.ArrayOps;" << endl; | 1890 s << "private import qt.gui.ArrayOps;" << endl; |
1891 | |
1892 s << "private import " << d_class->package() << ".ArrayOps2;" << endl; | |
1888 | 1893 |
1889 if (!d_class->enums().isEmpty()) | 1894 if (!d_class->enums().isEmpty()) |
1890 s << "public import " << d_class->package() << "." << d_class->name() << "_enum;" << endl << endl; | 1895 s << "public import " << d_class->package() << "." << d_class->name() << "_enum;" << endl << endl; |
1891 | 1896 |
1892 s << "// automatic imports-------------" << endl; | 1897 s << "// automatic imports-------------" << endl; |