comparison generator/cppimplgenerator.cpp @ 81:1750a803af74

return values as pointers
author eldar
date Sun, 24 May 2009 15:45:33 +0000
parents a5cc4ada07f5
children 64b874c86f9b
comparison
equal deleted inserted replaced
80:85c59c4e5f19 81:1750a803af74
275 return_type = jniName(new_return_type); 275 return_type = jniName(new_return_type);
276 } 276 }
277 277
278 // qtd 278 // qtd
279 if (f_type) { 279 if (f_type) {
280 if (f_type->name() == "QModelIndex") 280 if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD())
281 return_type = "void"; 281 return_type = "void";
282 else if (f_type->typeEntry()->isStructInD())
283 return_type = f_type->typeEntry()->qualifiedCppName();
284 else if (f_type->isObject() || f_type->isReference() || f_type->isValue() || f_type->isQObject()) 282 else if (f_type->isObject() || f_type->isReference() || f_type->isValue() || f_type->isQObject())
285 return_type = "void*"; 283 return_type = "void*";
286 if (f_type->isVariant()) 284 if (f_type->isVariant())
287 return_type = "void*"; 285 return_type = "void*";
288 } 286 }
782 780
783 if (f_type) { 781 if (f_type) {
784 if (f_type->isTargetLangString()) 782 if (f_type->isTargetLangString())
785 s << INDENT << "char* ret_str = NULL;" << endl 783 s << INDENT << "char* ret_str = NULL;" << endl
786 << INDENT << "size_t ret_str_size = 0;" << endl; 784 << INDENT << "size_t ret_str_size = 0;" << endl;
785
787 if (f_type->name() == "QModelIndex") 786 if (f_type->name() == "QModelIndex")
788 s << INDENT << "QModelIndexAccessor __d_return_value;" << endl; 787 s << INDENT << "QModelIndexAccessor __d_return_value;" << endl;
788 else if (f_type->typeEntry()->isStructInD())
789 s << INDENT << f_type->typeEntry()->qualifiedCppName() << " __d_return_value;" << endl;
790
789 if (f_type->isContainer()) 791 if (f_type->isContainer())
790 s << INDENT << "void* __d_return_value;" << endl 792 s << INDENT << "void* __d_return_value;" << endl
791 << INDENT << "size_t __d_return_value_size;" << endl; 793 << INDENT << "size_t __d_return_value_size;" << endl;
792 } 794 }
793 795
825 else if ((f_type->isValue() && !f_type->typeEntry()->isStructInD()) || 827 else if ((f_type->isValue() && !f_type->typeEntry()->isStructInD()) ||
826 f_type->isVariant() ) 828 f_type->isVariant() )
827 s << f_type->name() << " *__qt_return_value = (" << f_type->name() << "*) "; 829 s << f_type->name() << " *__qt_return_value = (" << f_type->name() << "*) ";
828 else if (f_type->isObject() || f_type->isQObject()) 830 else if (f_type->isObject() || f_type->isQObject())
829 s << "return (" << f_type->name() <<"*) "; 831 s << "return (" << f_type->name() <<"*) ";
830 else if (f_type->name() == "QModelIndex") 832 else if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD())
831 ; 833 ;
832 else if ((options & NoReturnStatement) == 0) 834 else if ((options & NoReturnStatement) == 0)
833 s << "return "; 835 s << "return ";
834 836
835 if (f_type->isEnum() || f_type->isFlags()) 837 if (f_type->isEnum() || f_type->isFlags())
840 << "this->d_entity()"; 842 << "this->d_entity()";
841 843
842 if (f_type) { 844 if (f_type) {
843 if (f_type->isTargetLangString()) 845 if (f_type->isTargetLangString())
844 s << ", ret_str, ret_str_size"; 846 s << ", ret_str, ret_str_size";
845 if (f_type->name() == "QModelIndex") 847 if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD())
846 s << ", &__d_return_value"; 848 s << ", &__d_return_value";
847 if (f_type->isContainer()) 849 if (f_type->isContainer())
848 s << ", &__d_return_value, &__d_return_value_size"; 850 s << ", &__d_return_value, &__d_return_value_size";
849 } 851 }
850 852
861 s << INDENT << "QModelIndex __qt_return_value = qtd_to_QModelIndex( __d_return_value );" << endl; 863 s << INDENT << "QModelIndex __qt_return_value = qtd_to_QModelIndex( __d_return_value );" << endl;
862 #ifdef Q_OS_WIN32 864 #ifdef Q_OS_WIN32
863 s << "__qtd_dummy();" << endl; // hack!!! 865 s << "__qtd_dummy();" << endl; // hack!!!
864 #endif 866 #endif
865 s << INDENT << "return __qt_return_value;" << endl; 867 s << INDENT << "return __qt_return_value;" << endl;
866 } 868 } else if (f_type->typeEntry()->isStructInD())
869 s << INDENT << "return __d_return_value;" << endl;
867 870
868 if (f_type->isContainer()) { 871 if (f_type->isContainer()) {
869 writeJavaToQt(s, f_type, "__qt_return_value", "__d_return_value", 872 writeJavaToQt(s, f_type, "__qt_return_value", "__d_return_value",
870 function, 0, GlobalRefJObject); 873 function, 0, GlobalRefJObject);
871 s << INDENT << "return __qt_return_value;" << endl; 874 s << INDENT << "return __qt_return_value;" << endl;
891 s << "(void *d_entity"; 894 s << "(void *d_entity";
892 895
893 if (ret_type) { 896 if (ret_type) {
894 if (ret_type->isTargetLangString()) 897 if (ret_type->isTargetLangString())
895 s << ", char* ret_str, size_t ret_str_size"; 898 s << ", char* ret_str, size_t ret_str_size";
899
896 if (ret_type->name() == "QModelIndex") 900 if (ret_type->name() == "QModelIndex")
897 s << ", QModelIndexAccessor *__d_return_value"; 901 s << ", QModelIndexAccessor *__d_return_value";
902 else if(ret_type->typeEntry()->isStructInD())
903 s << ", " << ret_type->typeEntry()->qualifiedCppName() << " *__d_return_value";
904
898 if (ret_type->isContainer()) 905 if (ret_type->isContainer())
899 s << ", void** __d_arr_ptr, size_t* __d_arr_size"; 906 s << ", void** __d_arr_ptr, size_t* __d_arr_size";
900 } 907 }
901 908
902 if (d_function->arguments().size() > 0) 909 if (d_function->arguments().size() > 0)
1892 // return values as strings, arrays or QModelIndex'es we return as arguments 1899 // return values as strings, arrays or QModelIndex'es we return as arguments
1893 bool return_arg = false; 1900 bool return_arg = false;
1894 if (f_type) { 1901 if (f_type) {
1895 if (f_type->isTargetLangString() || 1902 if (f_type->isTargetLangString() ||
1896 f_type->isContainer() || 1903 f_type->isContainer() ||
1897 f_type->name() == "QModelIndex") 1904 f_type->name() == "QModelIndex" ||
1905 f_type->typeEntry()->isStructInD())
1898 return_arg = true; 1906 return_arg = true;
1899 1907
1900 if (return_arg && nativeArgCount > 0) 1908 if (return_arg && nativeArgCount > 0)
1901 s << "," << endl << " "; 1909 s << "," << endl << " ";
1902 1910
1903 if (f_type->isTargetLangString() || f_type->isContainer()) 1911 if (f_type->isTargetLangString() || f_type->isContainer())
1904 s << "void*"; 1912 s << "void*";
1905 else if (f_type->name() == "QModelIndex") 1913 else if (f_type->name() == "QModelIndex")
1906 s << "QModelIndexAccessor*"; 1914 s << "QModelIndexAccessor*";
1915 else if (f_type->typeEntry()->isStructInD())
1916 s << f_type->typeEntry()->qualifiedCppName() << " *";
1907 1917
1908 if(return_arg) { 1918 if(return_arg) {
1909 s << " __d_return_value"; 1919 s << " __d_return_value";
1910 nativeArgCount++; 1920 nativeArgCount++;
1911 } 1921 }
1920 1930
1921 QString arg_name = argument->indexedName(); 1931 QString arg_name = argument->indexedName();
1922 1932
1923 if (nativeArgCount > 0) 1933 if (nativeArgCount > 0)
1924 s << "," << endl << " "; 1934 s << "," << endl << " ";
1925 // if QString argument we have to pass DArrat 1935
1936 // if QString argument we have to pass DArray
1926 if ((te && te->qualifiedCppName() == "QString") || d_type->isTargetLangString()) { 1937 if ((te && te->qualifiedCppName() == "QString") || d_type->isTargetLangString()) {
1927 if (d_export) 1938 if (d_export)
1928 s << "string " << arg_name; 1939 s << "string " << arg_name;
1929 else 1940 else
1930 s << "DArray " << arg_name; 1941 s << "DArray " << arg_name;
2108 // qtd s << INDENT << "QTJAMBI_DEBUG_TRACE(\"(native) -> leaving: " 2119 // qtd s << INDENT << "QTJAMBI_DEBUG_TRACE(\"(native) -> leaving: "
2109 // << java_function_signature << "\");"; 2120 // << java_function_signature << "\");";
2110 2121
2111 if (function_type && function_type->name() != "QModelIndex") { 2122 if (function_type && function_type->name() != "QModelIndex") {
2112 if(function_type->typeEntry()->isStructInD()) 2123 if(function_type->typeEntry()->isStructInD())
2113 s << endl << INDENT << "return " << qt_return_value << ";"; 2124 ; //s << endl << INDENT << "return " << qt_return_value << ";";
2114 else if (!function_type->isTargetLangString() && !function_type->isContainer()) 2125 else if (!function_type->isTargetLangString() && !function_type->isContainer())
2115 s << endl << INDENT << "return " << java_return_value << ";"; 2126 s << endl << INDENT << "return " << java_return_value << ";";
2116 } 2127 }
2117 2128
2118 } else { 2129 } else {
2138 const TypeEntry *te = d_type->typeEntry(); 2149 const TypeEntry *te = d_type->typeEntry();
2139 if ((te && d_type->isNativePointer() && te->name() == "QString")) 2150 if ((te && d_type->isNativePointer() && te->name() == "QString"))
2140 s << QString(" _d_toUtf8(__qt_%1.utf16(), __qt_%1.size(), &%1);").arg(argument->indexedName()) << endl; 2151 s << QString(" _d_toUtf8(__qt_%1.utf16(), __qt_%1.size(), &%1);").arg(argument->indexedName()) << endl;
2141 } 2152 }
2142 } 2153 }
2143
2144 2154
2145 void CppImplGenerator::writeAssignment(QTextStream &s, const QString &destName, const QString &srcName, 2155 void CppImplGenerator::writeAssignment(QTextStream &s, const QString &destName, const QString &srcName,
2146 const AbstractMetaType *java_type) 2156 const AbstractMetaType *java_type)
2147 { 2157 {
2148 if (java_type->isArray()) { 2158 if (java_type->isArray()) {
2215 2225
2216 writeQtToJava(s, getter->type(), tmp_name, java_return_value, 0, -1, EnumAsInts); 2226 writeQtToJava(s, getter->type(), tmp_name, java_return_value, 0, -1, EnumAsInts);
2217 if (getter->type()->isTargetLangString() || getter->type()->name() == "QModelIndex") 2227 if (getter->type()->isTargetLangString() || getter->type()->name() == "QModelIndex")
2218 ; 2228 ;
2219 else if(getter->type()->typeEntry()->isStructInD()) 2229 else if(getter->type()->typeEntry()->isStructInD())
2220 s << INDENT << "return " << tmp_name << ";" << endl; 2230 ; //s << INDENT << "return " << tmp_name << ";" << endl;
2221 else 2231 else
2222 s << INDENT << "return " << java_return_value << ";" << endl; 2232 s << INDENT << "return " << java_return_value << ";" << endl;
2223 } 2233 }
2224 s << "}" << endl << endl; 2234 s << "}" << endl << endl;
2225 } 2235 }
2946 s << INDENT << "QModelIndexAccessor tmp_index = qtd_from_QModelIndex(" << qt_name << ");" << endl 2956 s << INDENT << "QModelIndexAccessor tmp_index = qtd_from_QModelIndex(" << qt_name << ");" << endl
2947 << INDENT << "QModelIndexAccessor *" << java_name << " = &tmp_index;" << endl; 2957 << INDENT << "QModelIndexAccessor *" << java_name << " = &tmp_index;" << endl;
2948 else 2958 else
2949 s << INDENT << "*" << java_name << " = qtd_from_QModelIndex(" << qt_name << ");" << endl; 2959 s << INDENT << "*" << java_name << " = qtd_from_QModelIndex(" << qt_name << ");" << endl;
2950 2960
2951 } else if(java_type->typeEntry()->isStructInD()) { 2961 } else if (java_type->typeEntry()->isStructInD()) {
2952 s << INDENT << java_type->typeEntry()->name() << " *" << java_name << " = (" << java_type->typeEntry()->name() << " *) &" 2962 if (option & BoxedPrimitive) {
2953 << qt_name << ";" << endl; // do nothing 2963 s << INDENT << java_type->typeEntry()->name() << " *" << java_name << " = ("
2964 << java_type->typeEntry()->name() << " *) &" << qt_name << ";" << endl;
2965 } else {
2966 s << INDENT << "*" << java_name << " = " << qt_name << ";" << endl;
2967 }
2954 } else if (java_type->isArray() && java_type->arrayElementType()->isPrimitive()) { 2968 } else if (java_type->isArray() && java_type->arrayElementType()->isPrimitive()) {
2955 AbstractMetaType *elementType = java_type->arrayElementType(); 2969 AbstractMetaType *elementType = java_type->arrayElementType();
2956 /* qtd 2970 /* qtd
2957 s << INDENT << translateType(java_type, option) << " " << java_name << " = __jni_env->" << newXxxArray(elementType) 2971 s << INDENT << translateType(java_type, option) << " " << java_name << " = __jni_env->" << newXxxArray(elementType)
2958 << "(" << java_type->arrayElementCount() << ");" << endl; 2972 << "(" << java_type->arrayElementCount() << ");" << endl;
2994 s << INDENT << "jobject " << java_name << " = qtjambi_from_jobjectwrapper(__jni_env, " 3008 s << INDENT << "jobject " << java_name << " = qtjambi_from_jobjectwrapper(__jni_env, "
2995 << qt_name << ");" << endl; 3009 << qt_name << ");" << endl;
2996 } else if (java_type->isVariant()) { 3010 } else if (java_type->isVariant()) {
2997 s << INDENT << "QVariant *" << java_name 3011 s << INDENT << "QVariant *" << java_name
2998 << " = new QVariant(" << qt_name << ");" << endl; 3012 << " = new QVariant(" << qt_name << ");" << endl;
2999
3000 } else if (java_type->isTargetLangString()) { 3013 } else if (java_type->isTargetLangString()) {
3001 if(java_type->typeEntry()->qualifiedCppName() == "QStringRef") { 3014 if(java_type->typeEntry()->qualifiedCppName() == "QStringRef") {
3002 s << INDENT << "const QString *str_ref = " << qt_name << ".string();" << endl 3015 s << INDENT << "const QString *str_ref = " << qt_name << ".string();" << endl
3003 << INDENT << "if(str_ref)" << endl 3016 << INDENT << "if(str_ref)" << endl
3004 << INDENT << " _d_toUtf8(str_ref->utf16(), str_ref->size(), " << java_name << ");" << endl 3017 << INDENT << " _d_toUtf8(str_ref->utf16(), str_ref->size(), " << java_name << ");" << endl
3642 else 3655 else
3643 return d_name + QString(java_type->indirections(), '*'); 3656 return d_name + QString(java_type->indirections(), '*');
3644 } else { 3657 } else {
3645 return d_name + QString(java_type->indirections(), '*'); 3658 return d_name + QString(java_type->indirections(), '*');
3646 } 3659 }
3647 } 3660 }
3648 3661
3649 void CppImplGenerator::writeExtraIncludes(QTextStream &s, const AbstractMetaClass *java_class) 3662 void CppImplGenerator::writeExtraIncludes(QTextStream &s, const AbstractMetaClass *java_class)
3650 { 3663 {
3651 IncludeList includes = java_class->typeEntry()->extraIncludes(); 3664 IncludeList includes = java_class->typeEntry()->extraIncludes();
3652 qSort(includes.begin(), includes.end()); 3665 qSort(includes.begin(), includes.end());