# HG changeset patch # User eldar # Date 1243179933 0 # Node ID 1750a803af7430021d8c4e3f802d9b34d226f0df # Parent 85c59c4e5f192615c53835ea7cc2acaa4b9a73e7 return values as pointers diff -r 85c59c4e5f19 -r 1750a803af74 generator/cppimplgenerator.cpp --- a/generator/cppimplgenerator.cpp Sun May 24 15:25:41 2009 +0000 +++ b/generator/cppimplgenerator.cpp Sun May 24 15:45:33 2009 +0000 @@ -277,10 +277,8 @@ // qtd if (f_type) { - if (f_type->name() == "QModelIndex") + if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) return_type = "void"; - else if (f_type->typeEntry()->isStructInD()) - return_type = f_type->typeEntry()->qualifiedCppName(); else if (f_type->isObject() || f_type->isReference() || f_type->isValue() || f_type->isQObject()) return_type = "void*"; if (f_type->isVariant()) @@ -784,8 +782,12 @@ if (f_type->isTargetLangString()) s << INDENT << "char* ret_str = NULL;" << endl << INDENT << "size_t ret_str_size = 0;" << endl; + if (f_type->name() == "QModelIndex") s << INDENT << "QModelIndexAccessor __d_return_value;" << endl; + else if (f_type->typeEntry()->isStructInD()) + s << INDENT << f_type->typeEntry()->qualifiedCppName() << " __d_return_value;" << endl; + if (f_type->isContainer()) s << INDENT << "void* __d_return_value;" << endl << INDENT << "size_t __d_return_value_size;" << endl; @@ -827,7 +829,7 @@ s << f_type->name() << " *__qt_return_value = (" << f_type->name() << "*) "; else if (f_type->isObject() || f_type->isQObject()) s << "return (" << f_type->name() <<"*) "; - else if (f_type->name() == "QModelIndex") + else if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) ; else if ((options & NoReturnStatement) == 0) s << "return "; @@ -842,7 +844,7 @@ if (f_type) { if (f_type->isTargetLangString()) s << ", ret_str, ret_str_size"; - if (f_type->name() == "QModelIndex") + if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) s << ", &__d_return_value"; if (f_type->isContainer()) s << ", &__d_return_value, &__d_return_value_size"; @@ -863,7 +865,8 @@ s << "__qtd_dummy();" << endl; // hack!!! #endif s << INDENT << "return __qt_return_value;" << endl; - } + } else if (f_type->typeEntry()->isStructInD()) + s << INDENT << "return __d_return_value;" << endl; if (f_type->isContainer()) { writeJavaToQt(s, f_type, "__qt_return_value", "__d_return_value", @@ -893,8 +896,12 @@ if (ret_type) { if (ret_type->isTargetLangString()) s << ", char* ret_str, size_t ret_str_size"; + if (ret_type->name() == "QModelIndex") s << ", QModelIndexAccessor *__d_return_value"; + else if(ret_type->typeEntry()->isStructInD()) + s << ", " << ret_type->typeEntry()->qualifiedCppName() << " *__d_return_value"; + if (ret_type->isContainer()) s << ", void** __d_arr_ptr, size_t* __d_arr_size"; } @@ -1894,7 +1901,8 @@ if (f_type) { if (f_type->isTargetLangString() || f_type->isContainer() || - f_type->name() == "QModelIndex") + f_type->name() == "QModelIndex" || + f_type->typeEntry()->isStructInD()) return_arg = true; if (return_arg && nativeArgCount > 0) @@ -1904,6 +1912,8 @@ s << "void*"; else if (f_type->name() == "QModelIndex") s << "QModelIndexAccessor*"; + else if (f_type->typeEntry()->isStructInD()) + s << f_type->typeEntry()->qualifiedCppName() << " *"; if(return_arg) { s << " __d_return_value"; @@ -1922,7 +1932,8 @@ if (nativeArgCount > 0) s << "," << endl << " "; - // if QString argument we have to pass DArrat + + // if QString argument we have to pass DArray if ((te && te->qualifiedCppName() == "QString") || d_type->isTargetLangString()) { if (d_export) s << "string " << arg_name; @@ -2110,7 +2121,7 @@ if (function_type && function_type->name() != "QModelIndex") { if(function_type->typeEntry()->isStructInD()) - s << endl << INDENT << "return " << qt_return_value << ";"; + ; //s << endl << INDENT << "return " << qt_return_value << ";"; else if (!function_type->isTargetLangString() && !function_type->isContainer()) s << endl << INDENT << "return " << java_return_value << ";"; } @@ -2141,7 +2152,6 @@ } } - void CppImplGenerator::writeAssignment(QTextStream &s, const QString &destName, const QString &srcName, const AbstractMetaType *java_type) { @@ -2217,7 +2227,7 @@ if (getter->type()->isTargetLangString() || getter->type()->name() == "QModelIndex") ; else if(getter->type()->typeEntry()->isStructInD()) - s << INDENT << "return " << tmp_name << ";" << endl; + ; //s << INDENT << "return " << tmp_name << ";" << endl; else s << INDENT << "return " << java_return_value << ";" << endl; } @@ -2948,9 +2958,13 @@ else s << INDENT << "*" << java_name << " = qtd_from_QModelIndex(" << qt_name << ");" << endl; - } else if(java_type->typeEntry()->isStructInD()) { - s << INDENT << java_type->typeEntry()->name() << " *" << java_name << " = (" << java_type->typeEntry()->name() << " *) &" - << qt_name << ";" << endl; // do nothing + } else if (java_type->typeEntry()->isStructInD()) { + if (option & BoxedPrimitive) { + s << INDENT << java_type->typeEntry()->name() << " *" << java_name << " = (" + << java_type->typeEntry()->name() << " *) &" << qt_name << ";" << endl; + } else { + s << INDENT << "*" << java_name << " = " << qt_name << ";" << endl; + } } else if (java_type->isArray() && java_type->arrayElementType()->isPrimitive()) { AbstractMetaType *elementType = java_type->arrayElementType(); /* qtd @@ -2996,7 +3010,6 @@ } else if (java_type->isVariant()) { s << INDENT << "QVariant *" << java_name << " = new QVariant(" << qt_name << ");" << endl; - } else if (java_type->isTargetLangString()) { if(java_type->typeEntry()->qualifiedCppName() == "QStringRef") { s << INDENT << "const QString *str_ref = " << qt_name << ".string();" << endl @@ -3644,7 +3657,7 @@ } else { return d_name + QString(java_type->indirections(), '*'); } - } +} void CppImplGenerator::writeExtraIncludes(QTextStream &s, const AbstractMetaClass *java_class) { diff -r 85c59c4e5f19 -r 1750a803af74 generator/dgenerator.cpp --- a/generator/dgenerator.cpp Sun May 24 15:25:41 2009 +0000 +++ b/generator/dgenerator.cpp Sun May 24 15:45:33 2009 +0000 @@ -126,9 +126,9 @@ if (!d_type) { s = "void"; - } else if (d_type->typeEntry()->qualifiedCppName() == "QChar") + } else if (d_type->typeEntry()->qualifiedCppName() == "QChar") { s = "wchar" + QString(d_type->actualIndirections(), '*'); - else if (d_type->typeEntry() && d_type->typeEntry()->qualifiedCppName() == "QString") { + } else if (d_type->typeEntry() && d_type->typeEntry()->qualifiedCppName() == "QString") { s = "string"; } else if (d_type->isArray()) { s = translateType(d_type->arrayElementType(), context) + "[]"; @@ -668,29 +668,29 @@ if(return_type->name() == "QModelIndex") s << INDENT << "QModelIndex res;" << endl; + else if (return_type->typeEntry()->isStructInD()) + s << INDENT << return_type->name() << " res;" << endl; if(return_type->isContainer()) s << INDENT << this->translateType(d_function->type(), d_function->ownerClass(), NoOption) << " res;" << endl; } + //returning string or a struct + bool return_in_arg = return_type && (return_type->isTargetLangString() || + return_type->name() == "QModelIndex" || + return_type->isContainer() || + return_type->typeEntry()->isStructInD()); + + s << INDENT; if ( (has_return_type && d_function->argumentReplaced(0).isEmpty() ) || d_function->isConstructor()) { //qtd if(d_function->type() && d_function->type()->isQObject()) { // qtd s << "void *__qt_return_value = "; - } else if(d_function->type() && (d_function->type()->isTargetLangString() || - d_function->type()->name() == "QModelIndex" || - d_function->type()->isContainer())) // qtd + } else if(return_in_arg) // qtd ; -/* qtd2 not sure else if (needs_return_variable) { - if (new_return_type.isEmpty()) - s << translateType(return_type, d_function->implementingClass()); - else - s << new_return_type; - - s << " __qt_return_value = "; - }*/ else if (d_function->isConstructor()) { // qtd + else if (d_function->isConstructor()) { // qtd s << "void* __qt_return_value = "; - } else if (return_type && return_type->isValue() && !return_type->typeEntry()->isStructInD()) { + } else if (return_type && return_type->isValue() && !return_type->typeEntry()->isStructInD()) { s << "void* __qt_return_value = "; } else if (return_type && return_type->isVariant()) { s << "void* __qt_return_value = "; @@ -762,10 +762,6 @@ s << ", "; } - //returning string or a struct - bool return_in_arg = d_function->type() && (d_function->type()->isTargetLangString() || - d_function->type()->name() == "QModelIndex" || - d_function->type()->isContainer()); if(return_in_arg) { // qtd if (!d_function->isStatic() && !d_function->isConstructor()) // qtd s << ", "; @@ -794,18 +790,18 @@ s << arg_name << " is null ? null : " << arg_name << ".__ptr_" << te->designatedInterface()->name(); else if (modified_type == "string" /* && type->fullName() == "char" */) { s << "toStringz(" << arg_name << ")"; - } else if (type->isArray()) + } else if (type->isArray()) { s << arg_name << ".ptr"; - else if(type->isContainer()) { + } else if(type->isContainer()) { const ContainerTypeEntry *cte = static_cast(te); if(isLinearContainer(cte)) s << QString("%1.ptr, %1.length").arg(arg_name); - } else if (type->typeEntry()->qualifiedCppName() == "QChar") + } else if (type->typeEntry()->qualifiedCppName() == "QChar") { s << arg_name; - else if (type->isTargetLangString() || (te && te->qualifiedCppName() == "QString")) + } else if (type->isTargetLangString() || (te && te->qualifiedCppName() == "QString")) { s << arg_name; - else if (type->isTargetLangEnum() || type->isTargetLangFlags()) { + } else if (type->isTargetLangEnum() || type->isTargetLangFlags()) { s << arg_name; // qtd s << arg->argumentName() << ".value()"; } else if (!type->hasNativeId() && !(te->isValue() && type->isNativePointer())) { // qtd2 hack for QStyleOption not being a nativeId based for some reason @@ -853,9 +849,9 @@ // return value marschalling if(return_type) { if ( ( has_return_type && d_function->argumentReplaced(0).isEmpty() )/* || d_function->isConstructor()*/) // qtd - if(d_function->type()->isQObject()) { - - QString type_name = d_function->type()->name(); + if(return_type->isQObject()) { + + QString type_name = return_type->name(); const ComplexTypeEntry *ctype = static_cast(d_function->type()->typeEntry()); if(ctype->isAbstract()) type_name = type_name + "_ConcreteWrapper"; @@ -868,12 +864,12 @@ << INDENT << " new_obj.__no_real_delete = true;" << endl << INDENT << " return new_obj;" << endl << INDENT << "} else" << endl - << INDENT << " return cast(" << d_function->type()->name() << ") d_obj;" << endl; + << INDENT << " return cast(" << return_type->name() << ") d_obj;" << endl; } if (return_type->isValue() && !return_type->typeEntry()->isStructInD()) - s << INDENT << "return new " << d_function->type()->name() << "(__qt_return_value, false);" << endl; + s << INDENT << "return new " << return_type->name() << "(__qt_return_value, false);" << endl; if (return_type->isVariant()) s << INDENT << "return new QVariant(__qt_return_value, false);" << endl; @@ -887,13 +883,13 @@ << INDENT << QString("return __m_%1;").arg(d_function->name()) << endl; else { QString type_name = return_type->name(); - const ComplexTypeEntry *ctype = static_cast(d_function->type()->typeEntry()); + const ComplexTypeEntry *ctype = static_cast(return_type->typeEntry()); if(ctype->isAbstract()) type_name = type_name + "_ConcreteWrapper"; - QString return_type_name = d_function->type()->name(); + QString return_type_name = return_type->name(); if(return_type->typeEntry()->designatedInterface()) - return_type_name = d_function->type()->typeEntry()->designatedInterface()->name(); + return_type_name = return_type->typeEntry()->designatedInterface()->name(); AbstractMetaClass *classForTypeEntry = NULL; // search in AbstractMetaClass list for return type @@ -904,12 +900,12 @@ classForTypeEntry = cls; }*/ - classForTypeEntry = ClassFromEntry::get(d_function->type()->typeEntry()); + classForTypeEntry = ClassFromEntry::get(return_type->typeEntry()); // if class has virtual functions then it has classname_entity function so // we can look for D Object pointer. otherwise create new wrapper if (classForTypeEntry != NULL && classForTypeEntry->hasVirtualFunctions()) { - s << INDENT << "void* d_obj = __" << return_type->name() << "_entity(__qt_return_value);" << endl + s << INDENT << "void* d_obj = __" << d_function->type()->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 @@ -926,7 +922,6 @@ } s << endl; } - if (return_type->isArray()) { s << INDENT << "return __qt_return_value[0 .. " << return_type->arrayElementCount() << "];" << endl; } @@ -1910,8 +1905,8 @@ s << "public import qt.QGlobal;" << endl << "public import qt.core.Qt;" << endl << "private import qt.QtDObject;" << endl - << "private import qt.qtd.Array;" << endl - << "private import qt.core.QString;" << endl; + << "private import qt.core.QString;" << endl + << "private import qt.qtd.Array;" << endl; if (d_class->isQObject()) { s << "public import qt.Signal;" << endl; if (d_class->name() != "QObject") @@ -2393,18 +2388,18 @@ */ s << "}" << endl; - /* ---------------- injected free code ----------------*/ - const ComplexTypeEntry *class_type = d_class->typeEntry(); - Q_ASSERT(class_type); - - CodeSnipList code_snips = class_type->codeSnips(); - foreach (const CodeSnip &snip, code_snips) { - if (!d_class->isInterface() && snip.language == TypeSystem::TargetLangFreeCode) { - s << endl; - snip.formattedCode(s, INDENT); - } - } - /* --------------------------------------------------- */ + /* ---------------- injected free code ----------------*/ + const ComplexTypeEntry *class_type = d_class->typeEntry(); + Q_ASSERT(class_type); + + CodeSnipList code_snips = class_type->codeSnips(); + foreach (const CodeSnip &snip, code_snips) { + if (!d_class->isInterface() && snip.language == TypeSystem::TargetLangFreeCode) { + s << endl; + snip.formattedCode(s, INDENT); + } + } + /* --------------------------------------------------- */ interfaces = d_class->interfaces(); if (!interfaces.isEmpty()) { @@ -2872,7 +2867,7 @@ } else if (f_type && f_type->isTargetLangString()) s << "string _d_str = "; - else if (f_type && f_type->name() == "QModelIndex") + else if (f_type && (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD())) s << "*__d_return_value = "; else s << "auto return_value = "; @@ -2939,7 +2934,7 @@ s << INDENT << "*__d_arr_ptr = return_value.ptr;" << endl << INDENT << "*__d_arr_size = return_value.length;" << endl; // << INDENT << "addReference(return_value.ptr);" << endl; - else if (f_type->name() == "QModelIndex") + else if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) ; else s << INDENT << "return return_value;" << endl;