Mercurial > projects > qtd
comparison generator/dgenerator.cpp @ 288:f9559a957be9 signals
new signals and slots implementation
author | eldar |
---|---|
date | Sun, 08 Nov 2009 19:28:01 +0000 |
parents | 1f6923c8cba0 |
children | 19498f420252 |
comparison
equal
deleted
inserted
replaced
287:b6984b290e46 | 288:f9559a957be9 |
---|---|
61 m_docs_enabled(false), | 61 m_docs_enabled(false), |
62 m_native_jump_table(false), | 62 m_native_jump_table(false), |
63 m_recursive(0), | 63 m_recursive(0), |
64 m_isRecursive(false) | 64 m_isRecursive(false) |
65 { | 65 { |
66 excludedTypes << "long long" << "bool" << "int" << "QString" << "char" << "WId" | 66 excludedTypes << "qint64" << "bool" << "int" << "QString" << "char" << "WId" |
67 << "unsigned char" << "uint" << "double" << "short" << "float" | 67 << "unsigned char" << "uint" << "double" << "short" << "float" |
68 << "signed char" << "unsigned short" << "QBool" << "unsigned int" | 68 << "signed char" << "unsigned short" << "QBool" << "unsigned int" |
69 << "Qt::HANDLE" << "QChar" << "java.lang.JObjectWrapper" << "void" | 69 << "Qt::HANDLE" << "QChar" << "java.lang.JObjectWrapper" << "void" |
70 << "QLatin1String" << "unsigned long long" << "signed int" | 70 << "QLatin1String" << "unsigned long long" << "signed int" |
71 << "signed short" << "Array" << "GLuint" << "GLenum" << "GLint" | 71 << "signed short" << "Array" << "GLuint" << "GLenum" << "GLint" |
124 d_type = d_type->originalTemplateType(); | 124 d_type = d_type->originalTemplateType(); |
125 | 125 |
126 QString constPrefix, constPostfix; | 126 QString constPrefix, constPostfix; |
127 if (d_type && d_type->isConstant() && dVersion == 2) { | 127 if (d_type && d_type->isConstant() && dVersion == 2) { |
128 constPrefix = "const("; | 128 constPrefix = "const("; |
129 constPostfix = ") "; | 129 constPostfix = ")"; |
130 } | 130 } |
131 | 131 |
132 if (!d_type) { | 132 if (!d_type) { |
133 s = "void"; | 133 s = "void"; |
134 } else if (d_type->typeEntry()->qualifiedCppName() == "QChar") { | 134 } else if (d_type->typeEntry()->qualifiedCppName() == "QChar") { |
228 { | 228 { |
229 QString modified_type = d_function->typeReplaced(d_argument->argumentIndex() + 1); | 229 QString modified_type = d_function->typeReplaced(d_argument->argumentIndex() + 1); |
230 QString arg; | 230 QString arg; |
231 | 231 |
232 AbstractMetaType *type = d_argument->type(); | 232 AbstractMetaType *type = d_argument->type(); |
233 // if argument is "QString &" ref attribute needed | 233 // qtd2 if argument is "QString &" ref attribute needed FIXME maybe we need this not only for QString, but for other Value types?? |
234 if (type->typeEntry()->isValue() && type->isNativePointer() && type->typeEntry()->name() == "QString") | 234 if (type->typeEntry()->isValue() && type->isNativePointer() && type->typeEntry()->name() == "QString") |
235 arg = "ref "; | 235 arg = "ref "; |
236 | 236 |
237 if (modified_type.isEmpty()) | 237 if (modified_type.isEmpty()) |
238 arg += translateType(d_argument->type(), d_function->implementingClass(), (Option) options); | 238 arg += translateType(d_argument->type(), d_function->implementingClass(), (Option) options); |
981 QString functionName = d_function->isConstructor() ? "this" : d_function->name(); // qtd | 981 QString functionName = d_function->isConstructor() ? "this" : d_function->name(); // qtd |
982 // The actual function | 982 // The actual function |
983 if (!(d_function->isEmptyFunction() || d_function->isNormal() || d_function->isSignal())) | 983 if (!(d_function->isEmptyFunction() || d_function->isNormal() || d_function->isSignal())) |
984 option = Option(option | SkipReturnType); | 984 option = Option(option | SkipReturnType); |
985 writeFunctionAttributes(s, d_function, included_attributes, excluded_attributes, option); | 985 writeFunctionAttributes(s, d_function, included_attributes, excluded_attributes, option); |
986 /* | 986 |
987 if(d_function->isSignal()) | |
988 functionName += "_emit"; | |
989 */ | |
990 s << functionName << "("; | 987 s << functionName << "("; |
991 writeFunctionArguments(s, d_function, argument_count, option); | 988 writeFunctionArguments(s, d_function, argument_count, option); |
992 s << ")"; | 989 s << ")"; |
993 | 990 |
994 return result; | 991 return result; |
1711 { | 1708 { |
1712 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class); | 1709 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class); |
1713 | 1710 |
1714 QString attr; | 1711 QString attr; |
1715 | 1712 |
1713 // return; // #TODO Don't need handlers for now. Restore in conversion functions later | |
1714 | |
1716 s << "// signal handlers" << endl; | 1715 s << "// signal handlers" << endl; |
1717 foreach(AbstractMetaFunction *signal, signal_funcs) { | 1716 foreach(AbstractMetaFunction *signal, signal_funcs) { |
1718 QString sigExternName = signalExternName(d_class, signal); | 1717 QString sigExternName = signalExternName(d_class, signal); |
1719 | 1718 |
1720 s << "private " << attr << "extern(C) void " << sigExternName << "_connect(void* native_id);" << endl; | 1719 s << "private " << attr << "extern(C) void " << sigExternName << "_connect(void* native_id);" << endl; |
1769 << "(cast(void*)(" << arg_ptr << "), QtdObjectFlags.nativeOwnership);" << endl; | 1768 << "(cast(void*)(" << arg_ptr << "), QtdObjectFlags.nativeOwnership);" << endl; |
1770 } | 1769 } |
1771 s << endl; | 1770 s << endl; |
1772 } | 1771 } |
1773 // s << INDENT << "Stdout(\"" << d_class->name() << "\", \"" << signal->name() << "\").newline;" << endl; | 1772 // s << INDENT << "Stdout(\"" << d_class->name() << "\", \"" << signal->name() << "\").newline;" << endl; |
1774 s << INDENT << "d_object." << signal->name() << "_emit("; | 1773 s << INDENT << "//d_object." << signal->name() << "_emit("; |
1775 for (int j = 0; j<sz; ++j) { | 1774 for (int j = 0; j<sz; ++j) { |
1776 AbstractMetaArgument *argument = arguments.at(j); | 1775 AbstractMetaArgument *argument = arguments.at(j); |
1777 QString arg_name = argument->indexedName(); | 1776 QString arg_name = argument->indexedName(); |
1778 if (j != 0) | 1777 if (j != 0) |
1779 s << ", "; | 1778 s << ", "; |
1782 | 1781 |
1783 s << ");" << endl; | 1782 s << ");" << endl; |
1784 } | 1783 } |
1785 s << "}" << endl; | 1784 s << "}" << endl; |
1786 } | 1785 } |
1786 } | |
1787 | |
1788 AbstractMetaFunctionList DGenerator::generatedClassFunctions(const AbstractMetaClass *d_class) | |
1789 { | |
1790 AbstractMetaFunctionList r; | |
1791 AbstractMetaFunctionList d_funcs = d_class->functionsInTargetLang(); | |
1792 for (int i=0; i<d_funcs.size(); ++i) { | |
1793 AbstractMetaFunction *function = d_funcs.at(i); | |
1794 | |
1795 // If a method in an interface class is modified to be private, this should | |
1796 // not be present in the interface at all, only in the implementation. | |
1797 if (d_class->isInterface()) { | |
1798 uint includedAttributes = 0; | |
1799 uint excludedAttributes = 0; | |
1800 retrieveModifications(function, d_class, &excludedAttributes, &includedAttributes); | |
1801 if (includedAttributes & AbstractMetaAttributes::Private) | |
1802 continue; | |
1803 } | |
1804 | |
1805 if (!notWrappedYet(function)) // qtd2 | |
1806 r += function; | |
1807 } | |
1808 return r; | |
1787 } | 1809 } |
1788 | 1810 |
1789 void DGenerator::write(QTextStream &s, const AbstractMetaClass *d_class) | 1811 void DGenerator::write(QTextStream &s, const AbstractMetaClass *d_class) |
1790 { | 1812 { |
1791 ReportHandler::debugSparse("Generating class: " + d_class->fullName()); | 1813 ReportHandler::debugSparse("Generating class: " + d_class->fullName()); |
1907 << "private import qt.QtdObject;" << endl | 1929 << "private import qt.QtdObject;" << endl |
1908 << "private import qt.core.QString;" << endl | 1930 << "private import qt.core.QString;" << endl |
1909 << "private import qt.qtd.Array;" << endl; | 1931 << "private import qt.qtd.Array;" << endl; |
1910 if (d_class->isQObject()) { | 1932 if (d_class->isQObject()) { |
1911 s << "public import qt.Signal;" << endl | 1933 s << "public import qt.Signal;" << endl |
1934 << "public import qt.qtd.MOC;" << endl | |
1912 << "public import qt.core.QMetaObject;" << endl | 1935 << "public import qt.core.QMetaObject;" << endl |
1913 << "public import qt.qtd.Traits;" << endl; | 1936 << "public import qt.qtd.Traits;" << endl; |
1914 | 1937 |
1915 if (d_class->name() != "QObject") | 1938 if (d_class->name() != "QObject") |
1916 s << "public import qt.core.QObject;" << endl; | 1939 s << "public import qt.core.QObject;" << endl; |
2146 | 2169 |
2147 // Enums aliaases | 2170 // Enums aliaases |
2148 foreach (AbstractMetaEnum *d_enum, d_class->enums()) | 2171 foreach (AbstractMetaEnum *d_enum, d_class->enums()) |
2149 writeEnumAlias(s, d_enum); | 2172 writeEnumAlias(s, d_enum); |
2150 | 2173 |
2151 // Signals | 2174 // Signals |
2152 if (d_class->isQObject()) | 2175 if (d_class->isQObject()) |
2153 { | 2176 { |
2154 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class, false); | 2177 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class, false); |
2155 writeSignalSignatures(s, d_class, signal_funcs); | 2178 writeSignalSignatures(s, d_class, signal_funcs); |
2156 | 2179 |
2179 } | 2202 } |
2180 s << "// Functions" << endl; | 2203 s << "// Functions" << endl; |
2181 | 2204 |
2182 // Functions | 2205 // Functions |
2183 AbstractMetaFunctionList d_funcs = d_class->functionsInTargetLang(); | 2206 AbstractMetaFunctionList d_funcs = d_class->functionsInTargetLang(); |
2184 for (int i=0; i<d_funcs.size(); ++i) { | 2207 AbstractMetaFunctionList d_funcs_gen = generatedClassFunctions(d_class); |
2185 AbstractMetaFunction *function = d_funcs.at(i); | 2208 for (int i=0; i<d_funcs_gen.size(); ++i) { |
2186 | 2209 AbstractMetaFunction *function = d_funcs_gen.at(i); |
2187 // If a method in an interface class is modified to be private, this should | 2210 // if(function->isSlot()) |
2188 // not be present in the interface at all, only in the implementation. | 2211 // writeSlot(s, function); |
2189 if (d_class->isInterface()) { | 2212 writeFunction(s, function); |
2190 uint includedAttributes = 0; | 2213 // qtd s << function->minimalSignature() << endl; |
2191 uint excludedAttributes = 0; | |
2192 retrieveModifications(function, d_class, &excludedAttributes, &includedAttributes); | |
2193 if (includedAttributes & AbstractMetaAttributes::Private) | |
2194 continue; | |
2195 } | |
2196 | |
2197 if (!notWrappedYet(function)) // qtd2 | |
2198 writeFunction(s, function); | |
2199 // s << function->minimalSignature() << endl; | |
2200 } | 2214 } |
2201 if(d_class->isInterface()) | 2215 if(d_class->isInterface()) |
2202 s << endl << INDENT << "public void* __ptr_" << d_class->name() << "();" << endl << endl; | 2216 s << endl << INDENT << "public void* __ptr_" << d_class->name() << "();" << endl << endl; |
2203 | 2217 |
2204 | 2218 |
2240 << INDENT << "private native boolean __qt_signalInitialization(long ptr, String name);" << endl; | 2254 << INDENT << "private native boolean __qt_signalInitialization(long ptr, String name);" << endl; |
2241 } | 2255 } |
2242 */ | 2256 */ |
2243 if (d_class->isQObject()) | 2257 if (d_class->isQObject()) |
2244 writeQObjectFunctions(s, d_class); | 2258 writeQObjectFunctions(s, d_class); |
2259 | |
2260 // flag to mark the type of class (to use in templates to convert arguments) | |
2261 if (d_class->baseClassName().isEmpty()) | |
2262 { | |
2263 if (d_class->typeEntry()->isQObject()) | |
2264 s << INDENT << "public static enum __isQObjectType = true;" << endl << endl; | |
2265 else if (d_class->typeEntry()->isObject()) | |
2266 s << INDENT << "public static enum __isObjectType = true;" << endl << endl; | |
2267 else if (d_class->typeEntry()->isValue()) | |
2268 s << INDENT << "public static enum __isValueType = true;" << endl << endl; | |
2269 } | |
2245 | 2270 |
2246 // Add dummy constructor for use when constructing subclasses | 2271 // Add dummy constructor for use when constructing subclasses |
2247 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) { | 2272 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) { |
2248 s << endl | 2273 s << endl |
2249 << INDENT << "public " | 2274 << INDENT << "public " |
2631 m_isRecursive = false; | 2656 m_isRecursive = false; |
2632 } | 2657 } |
2633 | 2658 |
2634 | 2659 |
2635 if (d_class->isQObject()) | 2660 if (d_class->isQObject()) |
2636 { | 2661 writeQObjectFreeFunctions(s, d_class); |
2637 s << "private extern(C) void* qtd_" << d_class->name() << "_staticMetaObject();" << endl << endl | |
2638 << "private extern(C) void qtd_" << d_class->name() << "_createEntity(void* nativeId, void* dId);" << endl << endl; | |
2639 } | |
2640 } | 2662 } |
2641 | 2663 |
2642 void DGenerator::writeConversionFunction(QTextStream &s, const AbstractMetaClass *d_class) | 2664 void DGenerator::writeConversionFunction(QTextStream &s, const AbstractMetaClass *d_class) |
2643 { | 2665 { |
2644 const ComplexTypeEntry *ctype = d_class->typeEntry(); | 2666 const ComplexTypeEntry *ctype = d_class->typeEntry(); |
2672 << INDENT << "return return_value;" << endl; | 2694 << INDENT << "return return_value;" << endl; |
2673 } | 2695 } |
2674 s << "}" << endl << endl; | 2696 s << "}" << endl << endl; |
2675 } | 2697 } |
2676 | 2698 |
2699 void DGenerator::writeQObjectFreeFunctions(QTextStream &s, const AbstractMetaClass *d_class) | |
2700 { | |
2701 s << "private extern(C) QMetaObjectNative* qtd_" << d_class->name() << "_staticMetaObject();" << endl << endl | |
2702 << "private extern(C) void qtd_" << d_class->name() << "_createEntity(void* nativeId, void* dId);" << endl << endl; | |
2703 | |
2704 if (!d_class->isFinal()) | |
2705 s << "private extern(C) int qtd_" << d_class->name() << "_qt_metacall(void* __this_nativeId, QMetaObject.Call _c, int _id, void **_a);" | |
2706 << "private extern(C) int qtd_" << d_class->name() << "_qt_metacall_dispatch(void *d_entity, QMetaObject.Call _c, int _id, void **_a) {" | |
2707 << " auto d_object = cast(" << d_class->name() << ") d_entity;" | |
2708 << " return d_object.qt_metacall(_c, _id, _a);" | |
2709 << "}" << endl << endl; | |
2710 } | |
2711 | |
2712 void writeMetaMethodSignatures(QTextStream &s, const QString &var_name, AbstractMetaFunctionList meta_funcs) | |
2713 { | |
2714 s << INDENT << "private static const string[] " << var_name << " = ["; | |
2715 { | |
2716 Indentation indent(INDENT); | |
2717 for (int i = 0; i < meta_funcs.size(); ++i) | |
2718 { | |
2719 if (i) | |
2720 s << ", "; | |
2721 int j = 0; | |
2722 bool hasDefault = false; | |
2723 do // need this to look for default arguments and generate extra signatures | |
2724 { | |
2725 if (i || j) | |
2726 s << ", "; | |
2727 s << endl << INDENT << " \"" << meta_funcs.at(i)->minimalSignature(j) << "\""; | |
2728 AbstractMetaArgumentList args = meta_funcs.at(i)->arguments(); | |
2729 if(args.size() && j<args.size()) | |
2730 hasDefault = !args.at(args.size() - 1 - j)->defaultValueExpression().isEmpty(); | |
2731 else | |
2732 hasDefault = false; | |
2733 j++; | |
2734 } while (hasDefault); | |
2735 } | |
2736 } | |
2737 s << INDENT << "];" << endl << endl; | |
2738 } | |
2739 | |
2677 void DGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class) | 2740 void DGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class) |
2678 { | 2741 { |
2679 QString concreteArg; | 2742 AbstractMetaFunctionList d_funcs_gen = generatedClassFunctions(d_class); |
2743 AbstractMetaFunctionList slot_funcs; | |
2744 for (int i=0; i<d_funcs_gen.size(); ++i) { | |
2745 AbstractMetaFunction *function = d_funcs_gen.at(i); | |
2746 if(function->isSlot()) | |
2747 slot_funcs += function; | |
2748 } | |
2749 writeMetaMethodSignatures(s, "__slotSignatures", slot_funcs); | |
2750 | |
2751 QString concreteArg; | |
2680 if (d_class->isAbstract()) | 2752 if (d_class->isAbstract()) |
2681 concreteArg += ", " + d_class->name() + "_ConcreteWrapper"; | 2753 concreteArg += ", " + d_class->name() + "_ConcreteWrapper"; |
2754 | |
2755 if (!d_class->isFinal()) | |
2756 s << " int qt_metacall(QMetaObject.Call _c, int _id, void **_a) {" << endl | |
2757 << " return qtd_" << d_class->name() << "_qt_metacall(__nativeId, _c, _id, _a);" << endl | |
2758 << " }" << endl << endl; | |
2682 | 2759 |
2683 s << " private static QMetaObject _staticMetaObject;" << endl | 2760 s << " private static QMetaObject _staticMetaObject;" << endl |
2684 << " protected static void createStaticMetaObject() {" << endl | 2761 << " protected static void createStaticMetaObject() {" << endl |
2685 << " assert(!_staticMetaObject);" << endl | 2762 << " assert(!_staticMetaObject);" << endl |
2686 << " QMetaObject base;" << endl; | 2763 << " QMetaObject base;" << endl; |
2693 << " base = " << baseName << "._staticMetaObject;" << endl; | 2770 << " base = " << baseName << "._staticMetaObject;" << endl; |
2694 } | 2771 } |
2695 | 2772 |
2696 s << " _staticMetaObject = new QMetaObject(qtd_" << d_class->name() << "_staticMetaObject, base);" << endl | 2773 s << " _staticMetaObject = new QMetaObject(qtd_" << d_class->name() << "_staticMetaObject, base);" << endl |
2697 << " _staticMetaObject.construct!(" << d_class->name() << concreteArg << ");" << endl | 2774 << " _staticMetaObject.construct!(" << d_class->name() << concreteArg << ");" << endl |
2775 << " _populateMetaInfo();" << endl | |
2698 << " }" << endl << endl | 2776 << " }" << endl << endl |
2699 | 2777 |
2700 << " QMetaObject metaObject() {" << endl | 2778 << " QMetaObject metaObject() {" << endl |
2701 << " return _staticMetaObject;" << endl | 2779 << " return _staticMetaObject;" << endl |
2702 << " }" << endl << endl | 2780 << " }" << endl << endl |
2709 << " return static_cast!(" << d_class->name() << ")(_staticMetaObject.getObject(nativeId));" << endl | 2787 << " return static_cast!(" << d_class->name() << ")(_staticMetaObject.getObject(nativeId));" << endl |
2710 << " }" << endl << endl | 2788 << " }" << endl << endl |
2711 | 2789 |
2712 << " static void __createEntity(void* nativeId, void* dId) {" << endl | 2790 << " static void __createEntity(void* nativeId, void* dId) {" << endl |
2713 << " return qtd_" << d_class->name() << "_createEntity(nativeId, dId);" << endl | 2791 << " return qtd_" << d_class->name() << "_createEntity(nativeId, dId);" << endl |
2714 << " }" << endl << endl; | 2792 << " }" << endl << endl |
2793 | |
2794 << " private static void _populateMetaInfo() {" << endl | |
2795 << " int index;" << endl << endl; | |
2796 | |
2797 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class, false); | |
2798 | |
2799 int staticId = 0; | |
2800 for (int i = 0; i < signal_funcs.size(); ++i) | |
2801 { | |
2802 int j = 0; | |
2803 bool hasDefault = false; | |
2804 do // need this to look for default arguments and generate extra signatures | |
2805 { | |
2806 AbstractMetaFunction *fn = signal_funcs.at(i); | |
2807 s << " index = _staticMetaObject.indexOfMethod_Cpp(__signalSignatures[" << staticId << "]);" << endl | |
2808 << " _staticMetaObject.addMethod(new QMetaSignal(signature!(\"" << fn->name() << "\""; | |
2809 if(fn->arguments().size()-j > 0) | |
2810 s << ", "; | |
2811 writeMetaMethodArguments(s, fn, j); | |
2812 s << "), index));" << endl << endl; | |
2813 AbstractMetaArgumentList args = fn->arguments(); | |
2814 if(args.size() && j<args.size()) | |
2815 hasDefault = !args.at(args.size() - 1 - j)->defaultValueExpression().isEmpty(); | |
2816 else | |
2817 hasDefault = false; | |
2818 j++; | |
2819 staticId++; | |
2820 } while (hasDefault); | |
2821 } | |
2822 | |
2823 staticId = 0; | |
2824 for (int i = 0; i < slot_funcs.size(); ++i) | |
2825 { | |
2826 int j = 0; | |
2827 bool hasDefault = false; | |
2828 do // need this to look for default arguments and generate extra signatures | |
2829 { | |
2830 AbstractMetaFunction *fn = slot_funcs.at(i); | |
2831 s << " index = _staticMetaObject.indexOfMethod_Cpp(__slotSignatures[" << staticId << "]);" << endl | |
2832 << " _staticMetaObject.addMethod(new QMetaSlot(signature!(\"" << fn->name() << "\""; | |
2833 if(fn->arguments().size()-j > 0) | |
2834 s << ", "; | |
2835 writeMetaMethodArguments(s, fn, j); | |
2836 s << "), index));" << endl << endl; | |
2837 AbstractMetaArgumentList args = fn->arguments(); | |
2838 if(args.size() && j<args.size()) | |
2839 hasDefault = !args.at(args.size() - 1 - j)->defaultValueExpression().isEmpty(); | |
2840 else | |
2841 hasDefault = false; | |
2842 j++; | |
2843 staticId++; | |
2844 } while (hasDefault); | |
2845 } | |
2846 | |
2847 s << " }" << endl << endl; | |
2848 | |
2849 s << INDENT << "mixin Q_OBJECT_BIND;" << endl << endl; | |
2715 } | 2850 } |
2716 | 2851 |
2717 /* | 2852 /* |
2718 void DGenerator::writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class) | 2853 void DGenerator::writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class) |
2719 { | 2854 { |
2776 } | 2911 } |
2777 } | 2912 } |
2778 | 2913 |
2779 void DGenerator::writeSignalSignatures(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunctionList signal_funcs) | 2914 void DGenerator::writeSignalSignatures(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunctionList signal_funcs) |
2780 { | 2915 { |
2781 s << INDENT << "private const string[" << signal_funcs.size() << "] __signalSignatures = ["; | 2916 writeMetaMethodSignatures(s, "__signalSignatures", signal_funcs); |
2782 { | |
2783 Indentation indent(INDENT); | |
2784 for (int i = 0; i < signal_funcs.size(); ++i) | |
2785 { | |
2786 if (i) | |
2787 s << ", "; | |
2788 s << endl << INDENT << " \"" << signal_funcs.at(i)->minimalSignature() << "\""; | |
2789 } | |
2790 } | |
2791 s << INDENT << "];" << endl << endl; | |
2792 | 2917 |
2793 s << INDENT << "int signalSignature(int signalId, ref stringz signature) {" << endl; | 2918 s << INDENT << "int signalSignature(int signalId, ref stringz signature) {" << endl; |
2794 { | 2919 { |
2795 Indentation indent(INDENT); | 2920 Indentation indent(INDENT); |
2796 | 2921 |
2808 << INDENT << "return signalId;" << endl; | 2933 << INDENT << "return signalId;" << endl; |
2809 } | 2934 } |
2810 s << INDENT << "}" << endl; | 2935 s << INDENT << "}" << endl; |
2811 } | 2936 } |
2812 | 2937 |
2938 void DGenerator::writeMetaMethodArguments(QTextStream &s, const AbstractMetaFunction *d_function, int reduce) | |
2939 { | |
2940 bool withDefArgs = false; | |
2941 if(reduce == -1) { | |
2942 reduce = 0; | |
2943 withDefArgs = true; | |
2944 } | |
2945 | |
2946 AbstractMetaArgumentList arguments = d_function->arguments(); | |
2947 int sz = arguments.count() - reduce; | |
2948 | |
2949 for (int i=0; i<sz; ++i) { | |
2950 if(i != 0) | |
2951 s << ","; | |
2952 | |
2953 QString modifiedType = d_function->typeReplaced(i+1); | |
2954 | |
2955 if (modifiedType.isEmpty()) | |
2956 s << translateType(arguments.at(i)->type(), d_function->implementingClass(), BoxedPrimitive); | |
2957 else | |
2958 s << modifiedType; | |
2959 | |
2960 if (!arguments.at(i)->defaultValueExpression().isEmpty() && withDefArgs) // qtd | |
2961 s << " = " + arguments.at(i)->defaultValueExpression(); | |
2962 } | |
2963 } | |
2964 | |
2813 void DGenerator::writeSignal(QTextStream &s, const AbstractMetaFunction *d_function) | 2965 void DGenerator::writeSignal(QTextStream &s, const AbstractMetaFunction *d_function) |
2814 { | 2966 { |
2815 Q_ASSERT(d_function->isSignal()); | 2967 Q_ASSERT(d_function->isSignal()); |
2816 | 2968 |
2817 AbstractMetaArgumentList arguments = d_function->arguments(); | 2969 s << INDENT << "mixin BindQtSignal!(\"" << d_function->name() << "("; |
2818 int sz = arguments.count(); | 2970 |
2819 | 2971 writeMetaMethodArguments(s, d_function); |
2820 s << INDENT << "mixin BindQtSignal!(\"" << d_function->name() << "\""; | 2972 |
2821 | 2973 s << ")\");" << endl; |
2822 if (sz > 0) { | |
2823 for (int i=0; i<sz; ++i) { | |
2824 s << ", "; | |
2825 | |
2826 QString modifiedType = d_function->typeReplaced(i+1); | |
2827 | |
2828 if (modifiedType.isEmpty()) | |
2829 s << translateType(arguments.at(i)->type(), d_function->implementingClass(), BoxedPrimitive); | |
2830 else | |
2831 s << modifiedType; | |
2832 } | |
2833 } | |
2834 | |
2835 s << ");" << endl; | |
2836 } | 2974 } |
2837 | 2975 |
2838 void DGenerator::writeShellVirtualFunction(QTextStream &s, const AbstractMetaFunction *d_function, | 2976 void DGenerator::writeShellVirtualFunction(QTextStream &s, const AbstractMetaFunction *d_function, |
2839 const AbstractMetaClass *implementor, int id) | 2977 const AbstractMetaClass *implementor, int id) |
2840 { | 2978 { |