Mercurial > projects > qtd
comparison generator/cppimplgenerator.cpp @ 335:1e9092e20a67
merge signals branch into default
author | eldar1@eldar1-laptop |
---|---|
date | Sun, 07 Feb 2010 16:04:36 +0000 |
parents | 0cc996b7a601 |
children | 9fc85d7280ba |
comparison
equal
deleted
inserted
replaced
306:70f64e5b5942 | 335:1e9092e20a67 |
---|---|
503 if (!notWrappedYet(function)) { // qtd2 | 503 if (!notWrappedYet(function)) { // qtd2 |
504 s << " " << function->marshalledName() << "_dispatch = " | 504 s << " " << function->marshalledName() << "_dispatch = " |
505 "(pf" << function->marshalledName() << "_dispatch) virts[" << pos << "];" << endl; | 505 "(pf" << function->marshalledName() << "_dispatch) virts[" << pos << "];" << endl; |
506 } | 506 } |
507 } | 507 } |
508 | |
509 // D-side signal callbacks | 508 // D-side signal callbacks |
510 AbstractMetaFunctionList signal_funcs = signalFunctions(java_class); | 509 if (java_class->isQObject()) { |
511 for(int i = 0; i < signal_funcs.size(); i++) | 510 s << " qtd_" << java_class->name() << "_qt_metacall_dispatch = (QtMetacallCallback)sigs[0];" << endl |
512 s << " emit_callbacks_" << java_class->name() << "[" << i << "] = (EmitCallback)" | 511 << " qtd_" << java_class->name() << "_metaObject_dispatch = (MetaObjectCallback)sigs[1];" << endl; |
513 "sigs[" << i << "];" << endl; | 512 } |
514 | |
515 s << "}" << endl; | 513 s << "}" << endl; |
516 } | 514 } |
517 | 515 |
518 | 516 |
519 void CppImplGenerator::write(QTextStream &s, const AbstractMetaClass *java_class) | 517 void CppImplGenerator::write(QTextStream &s, const AbstractMetaClass *java_class) |
590 | 588 |
591 if (hasCustomDestructor(java_class)) */ | 589 if (hasCustomDestructor(java_class)) */ |
592 if (!java_class->isQObject()) | 590 if (!java_class->isQObject()) |
593 writeFinalDestructor(s, java_class); | 591 writeFinalDestructor(s, java_class); |
594 | 592 |
595 if (java_class->isQObject()) | 593 if (java_class->isQObject()) { |
594 writeQObjectEntity(s, java_class); | |
596 writeSignalsHandling(s, java_class); | 595 writeSignalsHandling(s, java_class); |
597 | 596 } |
598 if (shellClass) { | 597 if (shellClass) { |
599 foreach (AbstractMetaFunction *function, java_class->functions()) { | 598 foreach (AbstractMetaFunction *function, java_class->functions()) { |
600 if (function->isConstructor() && !function->isPrivate()) | 599 if (function->isConstructor() && !function->isPrivate()) |
601 writeShellConstructor(s, function); | 600 writeShellConstructor(s, function); |
602 } | 601 } |
707 | 706 |
708 writeSignalInitialization(s, java_class); | 707 writeSignalInitialization(s, java_class); |
709 */ | 708 */ |
710 // qtd writeJavaLangObjectOverrideFunctions(s, java_class); | 709 // qtd writeJavaLangObjectOverrideFunctions(s, java_class); |
711 | 710 |
711 if (java_class->typeEntry()->isValue()) | |
712 writeValueFunctions(s, java_class); | |
713 | |
712 if (java_class->isQObject()) | 714 if (java_class->isQObject()) |
713 { | 715 { |
714 s << endl << endl | 716 s << endl << endl |
715 << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_staticMetaObject() {" << endl | 717 << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_staticMetaObject() {" << endl |
716 << " return (void*)&" << java_class->name() << "::staticMetaObject;" << endl | 718 << " return (void*)&" << java_class->name() << "::staticMetaObject;" << endl |
717 << "}" << endl; | 719 << "}" << endl; |
718 } | 720 } |
719 | 721 |
722 if (java_class->typeEntry()->isValue()) | |
723 { | |
724 if (!java_class->typeEntry()->hasPrivateCopyConstructor()) // can do a copy if we have a public ctor or don't have any | |
725 { | |
726 QString argName = "orig"; | |
727 s << endl << endl | |
728 << "extern \"C\" DLL_PUBLIC void qtd_" << java_class->name() << "_placed_copy(void* " | |
729 << argName << ", void* place) {" << endl | |
730 << QString(" const %1& __qt_%2 = (const %1& ) *(%1 *)%2;").arg(shellClassName(java_class)).arg(argName) << endl | |
731 << QString(" %1 *result = new (place) %1 (__qt_%2);").arg(java_class->qualifiedCppName()).arg(argName) << endl; | |
732 // writeFinalConstructor(s, ctor, "result", "original", "(place)"); | |
733 s << "}"; | |
734 | |
735 s << endl << endl | |
736 << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_native_copy(void* " << argName << ") {" << endl | |
737 << QString(" const %1& __qt_%2 = (const %1& ) *(%1 *)%2;").arg(shellClassName(java_class)).arg(argName) << endl | |
738 << QString(" %1 *result = new %1 (__qt_%2);").arg(java_class->qualifiedCppName()).arg(argName) << endl | |
739 << " return result;" << endl; | |
740 s << "}"; | |
741 } | |
742 } | |
743 | |
720 s << endl << endl; | 744 s << endl << endl; |
721 | 745 |
722 priGenerator->addSource(java_class->package(), fileNameForClass(java_class)); | 746 priGenerator->addSource(java_class->package(), fileNameForClass(java_class)); |
747 } | |
748 | |
749 void CppImplGenerator::writeValueFunctions(QTextStream &s, const AbstractMetaClass *java_class) | |
750 { | |
751 s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isComplex() { return (bool) QTypeInfo<%2>::isComplex; }\n").arg(java_class->name()).arg(java_class->qualifiedCppName()); | |
752 s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isStatic() { return (bool) QTypeInfo<%2>::isStatic; }\n").arg(java_class->name()).arg(java_class->qualifiedCppName()); | |
753 s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isLarge() { return (bool) QTypeInfo<%2>::isLarge; }\n").arg(java_class->name()).arg(java_class->qualifiedCppName()); | |
754 s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isPointer() { return (bool) QTypeInfo<%2>::isPointer; }\n").arg(java_class->name()).arg(java_class->qualifiedCppName()); | |
755 s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isDummy() { return (bool) QTypeInfo<%2>::isDummy; }\n").arg(java_class->name()).arg(java_class->qualifiedCppName()); | |
723 } | 756 } |
724 | 757 |
725 void CppImplGenerator::writeVirtualDispatchFunction(QTextStream &s, const AbstractMetaFunction *function, bool d_export) | 758 void CppImplGenerator::writeVirtualDispatchFunction(QTextStream &s, const AbstractMetaFunction *function, bool d_export) |
726 { | 759 { |
727 uint options2 = ReturnType | ExternC; | 760 uint options2 = ReturnType | ExternC; |
780 s << INDENT << "QModelIndexAccessor __d_return_value;" << endl; | 813 s << INDENT << "QModelIndexAccessor __d_return_value;" << endl; |
781 else if (f_type->typeEntry()->isStructInD()) | 814 else if (f_type->typeEntry()->isStructInD()) |
782 s << INDENT << f_type->typeEntry()->qualifiedCppName() << " __d_return_value;" << endl; | 815 s << INDENT << f_type->typeEntry()->qualifiedCppName() << " __d_return_value;" << endl; |
783 | 816 |
784 if (f_type->isContainer()) | 817 if (f_type->isContainer()) |
785 s << INDENT << "void* __d_return_value;" << endl | 818 { |
786 << INDENT << "size_t __d_return_value_size;" << endl; | 819 if (isNativeContainer(f_type)) |
820 { | |
821 s << INDENT; | |
822 writeTypeInfo(s, f_type, ForceValueType); | |
823 s << "__d_return_value;" << endl; | |
824 } | |
825 else | |
826 s << INDENT << "void* __d_return_value;" << endl | |
827 << INDENT << "size_t __d_return_value_size;" << endl; | |
828 } | |
787 } | 829 } |
788 | 830 |
789 AbstractMetaArgumentList arguments = function->arguments(); | 831 AbstractMetaArgumentList arguments = function->arguments(); |
790 foreach (AbstractMetaArgument *argument, arguments) { | 832 foreach (AbstractMetaArgument *argument, arguments) { |
791 if (!function->argumentRemoved(argument->argumentIndex()+1)) { | 833 if (!function->argumentRemoved(argument->argumentIndex()+1)) { |
792 if (!argument->type()->isPrimitive() | 834 AbstractMetaType *atype = argument->type(); |
835 if (!atype->isPrimitive() | |
793 || !function->conversionRule(TypeSystem::NativeCode, argument->argumentIndex()+1).isEmpty()) { | 836 || !function->conversionRule(TypeSystem::NativeCode, argument->argumentIndex()+1).isEmpty()) { |
794 if(argument->type()->isContainer()) { | 837 if(atype->isContainer()) { |
795 QString arg_name = argument->indexedName(); | 838 QString arg_name = argument->indexedName(); |
796 s << INDENT << QString("DArray %1_arr;").arg(arg_name) << endl | 839 if(!isNativeContainer(atype)) |
797 << INDENT << QString("DArray *__d_%1 = &%1_arr;").arg(arg_name); | 840 writeQtToJava(s, |
798 | 841 argument->type(), |
799 writeQtToJava(s, | 842 arg_name, |
800 argument->type(), | 843 "__d_" + arg_name, |
801 arg_name, | 844 function, |
802 "__d_" + arg_name, | 845 argument->argumentIndex() + 1, |
803 function, | 846 Option(VirtualDispatch)); |
804 argument->argumentIndex() + 1, | |
805 Option(VirtualDispatch)); | |
806 } | 847 } |
807 } | 848 } |
808 } | 849 } |
809 } | 850 } |
810 | 851 |
836 | 877 |
837 if (f_type) { | 878 if (f_type) { |
838 if (f_type->isTargetLangString()) | 879 if (f_type->isTargetLangString()) |
839 s << ", &ret_str"; | 880 s << ", &ret_str"; |
840 if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) | 881 if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) |
841 s << ", &__d_return_value"; | 882 s << ", &__d_return_value"; // TODO should both be refactored into isNativeType function |
842 if (f_type->isContainer()) | 883 if (f_type->isContainer()) { |
843 s << ", &__d_return_value, &__d_return_value_size"; | 884 if ( ((const ContainerTypeEntry *)f_type->typeEntry())->isQList() ) |
885 s << ", &__d_return_value"; | |
886 else | |
887 s << ", &__d_return_value, &__d_return_value_size"; | |
888 } | |
844 } | 889 } |
845 | 890 |
846 if (function->arguments().size() > 0) | 891 if (function->arguments().size() > 0) |
847 s << ", "; | 892 s << ", "; |
848 writeFunctionCallArguments(s, function, QString(), Option(options | ForceEnumCast | SkipRemovedArguments | ExcludeConst | VirtualDispatch)); | 893 writeFunctionCallArguments(s, function, QString(), Option(options | ForceEnumCast | SkipRemovedArguments | ExcludeConst | VirtualDispatch)); |
860 s << INDENT << "return __qt_return_value;" << endl; | 905 s << INDENT << "return __qt_return_value;" << endl; |
861 } else if (f_type->typeEntry()->isStructInD()) | 906 } else if (f_type->typeEntry()->isStructInD()) |
862 s << INDENT << "return __d_return_value;" << endl; | 907 s << INDENT << "return __d_return_value;" << endl; |
863 | 908 |
864 if (f_type->isContainer()) { | 909 if (f_type->isContainer()) { |
865 writeJavaToQt(s, f_type, "__qt_return_value", "__d_return_value", | 910 if (isNativeContainer(f_type)) |
866 function, 0, GlobalRefJObject); | 911 s << INDENT << "return __d_return_value;" << endl; |
867 s << INDENT << "return __qt_return_value;" << endl; | 912 else |
913 { | |
914 writeJavaToQt(s, f_type, "__qt_return_value", "__d_return_value", | |
915 function, 0, GlobalRefJObject); | |
916 s << INDENT << "return __qt_return_value;" << endl; | |
917 } | |
868 } | 918 } |
869 | 919 |
870 if (f_type->isTargetLangString()) | 920 if (f_type->isTargetLangString()) |
871 s << INDENT << "return " << "QString::fromUtf8((const char*) ret_str.ptr, ret_str.length);" << endl; | 921 s << INDENT << "return " << "QString::fromUtf8((const char*) ret_str.ptr, ret_str.length);" << endl; |
872 | 922 |
896 if (ret_type->name() == "QModelIndex") | 946 if (ret_type->name() == "QModelIndex") |
897 s << ", QModelIndexAccessor *__d_return_value"; | 947 s << ", QModelIndexAccessor *__d_return_value"; |
898 else if(ret_type->typeEntry()->isStructInD()) | 948 else if(ret_type->typeEntry()->isStructInD()) |
899 s << ", " << ret_type->typeEntry()->qualifiedCppName() << " *__d_return_value"; | 949 s << ", " << ret_type->typeEntry()->qualifiedCppName() << " *__d_return_value"; |
900 | 950 |
901 if (ret_type->isContainer()) | 951 if (ret_type->isContainer()) { |
902 s << ", void** __d_arr_ptr, size_t* __d_arr_size"; | 952 if(isNativeContainer(ret_type)) { |
953 if(d_export) | |
954 s << ", " << DGenerator::translateType(ret_type, d_function->ownerClass(), NoOption) << "* __d_arr"; | |
955 else | |
956 s << ", void * __d_arr"; | |
957 } | |
958 else | |
959 s << ", void** __d_arr_ptr, size_t* __d_arr_size"; | |
960 } | |
903 } | 961 } |
904 | 962 |
905 if (d_function->arguments().size() > 0) | 963 if (d_function->arguments().size() > 0) |
906 s << ", "; | 964 s << ", "; |
907 | 965 |
917 QString arg_name = argument->indexedName(); | 975 QString arg_name = argument->indexedName(); |
918 | 976 |
919 if (d_type->name() == "QModelIndex") | 977 if (d_type->name() == "QModelIndex") |
920 s << "QModelIndexAccessor" << QString(d_type->actualIndirections(), '*') << " " << arg_name; | 978 s << "QModelIndexAccessor" << QString(d_type->actualIndirections(), '*') << " " << arg_name; |
921 else if (d_type->isContainer()) { | 979 else if (d_type->isContainer()) { |
922 if (d_export) { | 980 if ( isNativeContainer(d_type) ) |
981 s << "void* "; | |
982 else if (d_export) | |
923 s << DGenerator::translateType(d_type, d_function->ownerClass(), NoOption) << "* "; | 983 s << DGenerator::translateType(d_type, d_function->ownerClass(), NoOption) << "* "; |
924 } else | 984 else |
925 s << "DArray* "; | 985 s << "DArray* "; |
926 s << arg_name; | 986 s << arg_name; |
927 } else if (d_type->typeEntry()->isStructInD()) | 987 } else if (d_type->typeEntry()->isStructInD()) |
928 s << d_type->typeEntry()->qualifiedCppName() << QString(d_type->actualIndirections(), '*') | 988 s << d_type->typeEntry()->qualifiedCppName() << QString(d_type->actualIndirections(), '*') |
929 << " " << arg_name; | 989 << " " << arg_name; |
1215 | 1275 |
1216 s << "class " << entityName << " : public QObject, public QtD_QObjectEntity" << endl | 1276 s << "class " << entityName << " : public QObject, public QtD_QObjectEntity" << endl |
1217 << "{" << endl | 1277 << "{" << endl |
1218 << "public:" << endl | 1278 << "public:" << endl |
1219 << " Q_OBJECT_CHECK" << endl | 1279 << " Q_OBJECT_CHECK" << endl |
1220 << " virtual int qt_metacall(QMetaObject::Call, int, void **);" << endl << endl | 1280 << "// virtual int qt_metacall(QMetaObject::Call, int, void **);" << endl << endl |
1221 | 1281 |
1222 << " " << entityName << "(QObject *qObject, void *dId) : QObject(), QtD_QObjectEntity(qObject, dId) {}" << endl | 1282 << " " << entityName << "(QObject *qObject, void *dId) : QObject(), QtD_QObjectEntity(qObject, dId) {}" << endl |
1223 << "};" << endl << endl; | 1283 << "};" << endl << endl; |
1224 | 1284 |
1225 // QObject_Link::qt_metacall() | 1285 /* // QObject_Link::qt_metacall() |
1226 s << "int " << entityName << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl | 1286 s << "int " << entityName << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl |
1227 << "{" << endl | 1287 << "{" << endl |
1228 << " _id = QObject::qt_metacall(_c, _id, _a);" << endl | 1288 << " _id = QObject::qt_metacall(_c, _id, _a);" << endl |
1229 << " if (_id < 0 || _c != QMetaObject::InvokeMetaMethod)" << endl | 1289 << " if (_id < 0 || _c != QMetaObject::InvokeMetaMethod)" << endl |
1230 << " return _id;" << endl | 1290 << " return _id;" << endl |
1231 // << " Q_ASSERT(_id < 2);" << endl | |
1232 << " emit_callbacks_" << java_class->name() << "[_id](dId, _a);" << endl | 1291 << " emit_callbacks_" << java_class->name() << "[_id](dId, _a);" << endl |
1233 << " return -1;" << endl | 1292 << " return -1;" << endl |
1234 << "}" << endl << endl; | 1293 << "}" << endl << endl; |
1235 | 1294 */ |
1236 s << "extern \"C\" DLL_PUBLIC void qtd_" << className << "_createEntity(void *nativeId, void* dId)" << endl | 1295 s << "extern \"C\" DLL_PUBLIC void qtd_" << className << "_createEntity(void *nativeId, void* dId)" << endl |
1237 << "{" << endl | 1296 << "{" << endl |
1238 << " new " << entityName << "((QObject*)nativeId, dId);" << endl | 1297 << " new " << entityName << "((QObject*)nativeId, dId);" << endl |
1239 << "}" << endl << endl; | 1298 << "}" << endl << endl; |
1240 } | 1299 } |
1280 << " if (!strcmp(_clname, \"" << shellClassName(java_class) << "\"))" << endl | 1339 << " if (!strcmp(_clname, \"" << shellClassName(java_class) << "\"))" << endl |
1281 << " return static_cast<void*>(const_cast<" << shellClassName(java_class) << "*>(this));" << endl | 1340 << " return static_cast<void*>(const_cast<" << shellClassName(java_class) << "*>(this));" << endl |
1282 << " return " << java_class->qualifiedCppName() << "::qt_metacast(_clname);" << endl | 1341 << " return " << java_class->qualifiedCppName() << "::qt_metacast(_clname);" << endl |
1283 << "}" << endl << endl; | 1342 << "}" << endl << endl; |
1284 */ | 1343 */ |
1285 | 1344 /* |
1286 s << "int " << shellClassName(java_class) << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl | 1345 s << "int " << shellClassName(java_class) << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl |
1287 << "{" << endl; | 1346 << "{" << endl |
1288 | 1347 << " _id = " << java_class->qualifiedCppName() << "::qt_metacall(_c, _id, _a);" << endl |
1289 s << " _id = " << java_class->qualifiedCppName() << "::qt_metacall(_c, _id, _a);" << endl | |
1290 << " if (_id < 0 || _c != QMetaObject::InvokeMetaMethod)" << endl | 1348 << " if (_id < 0 || _c != QMetaObject::InvokeMetaMethod)" << endl |
1291 << " return _id;" << endl | 1349 << " return _id;" << endl |
1292 << " emit_callbacks_" << java_class->name() << "[_id](this->dId, _a);" << endl | 1350 << " emit_callbacks_" << java_class->name() << "[_id](this->dId, _a);" << endl |
1293 << " return -1;" << endl | 1351 << " return -1;" << endl |
1352 << "}" << endl << endl; | |
1353 */ | |
1354 | |
1355 if(cpp_shared) | |
1356 s << "MetaObjectCallback qtd_" << java_class->name() << "_metaObject_dispatch;" << endl | |
1357 << "QtMetacallCallback qtd_" << java_class->name() << "_qt_metacall_dispatch;" << endl; | |
1358 else | |
1359 s << "extern \"C\" const QMetaObject* qtd_" << java_class->name() << "_metaObject_dispatch(void *d_entity);" << endl | |
1360 << "extern \"C\" int qtd_" << java_class->name() << "_qt_metacall_dispatch(void *d_entity, QMetaObject::Call _c, int _id, void **_a);" << endl; | |
1361 | |
1362 s << endl | |
1363 << "const QMetaObject * " << shellClassName(java_class) << "::metaObject() const" << endl | |
1364 << "{" << endl | |
1365 << " return qtd_" << java_class->name() << "_metaObject_dispatch(this->dId);" << endl | |
1366 << "}" << endl << endl | |
1367 << "int " << shellClassName(java_class) << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl | |
1368 << "{" << endl | |
1369 << " return qtd_" << java_class->name() << "_qt_metacall_dispatch(this->dId, _c, _id, _a);" << endl | |
1370 << "}" << endl << endl | |
1371 | |
1372 << "int " << shellClassName(java_class) << "::__override_qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl | |
1373 << "{" << endl | |
1374 << " return " << java_class->qualifiedCppName() << "::qt_metacall(_c, _id, _a);" | |
1375 << "}" << endl << endl | |
1376 | |
1377 << "extern \"C\" DLL_PUBLIC int qtd_" << java_class->name() << "_qt_metacall(void* __this_nativeId, QMetaObject::Call _c, int _id, void **_a)" | |
1378 << "{" << endl | |
1379 << " " << shellClassName(java_class) << " *__qt_this = (" << shellClassName(java_class) << " *) __this_nativeId;" << endl | |
1380 << " return __qt_this->__override_qt_metacall(_c, _id, _a);" << endl | |
1294 << "}" << endl << endl; | 1381 << "}" << endl << endl; |
1295 } | 1382 } |
1296 | 1383 |
1297 void CppImplGenerator::writeSignalEmitter(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunction *function) | 1384 void CppImplGenerator::writeSignalEmitter(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunction *function) |
1298 { | 1385 { |
1339 s << endl << endl; | 1426 s << endl << endl; |
1340 } | 1427 } |
1341 | 1428 |
1342 void CppImplGenerator::writeSignalsHandling(QTextStream &s, const AbstractMetaClass *java_class) | 1429 void CppImplGenerator::writeSignalsHandling(QTextStream &s, const AbstractMetaClass *java_class) |
1343 { | 1430 { |
1431 return; // #TODO probably don't need this function at all | |
1432 | |
1344 s << "extern \"C\" typedef void (*EmitCallback)(void*, void**);" << endl; | 1433 s << "extern \"C\" typedef void (*EmitCallback)(void*, void**);" << endl; |
1345 AbstractMetaFunctionList signal_funcs = signalFunctions(java_class); | 1434 AbstractMetaFunctionList signal_funcs = signalFunctions(java_class); |
1346 | 1435 |
1347 if (cpp_shared) | 1436 if (cpp_shared) |
1348 if(signal_funcs.size() > 0) | 1437 if(signal_funcs.size() > 0) |
1367 s << ", "; | 1456 s << ", "; |
1368 s << "&" << signalExternName(java_class, signal) << "_handle"; | 1457 s << "&" << signalExternName(java_class, signal) << "_handle"; |
1369 } | 1458 } |
1370 s << endl << "};" << endl << endl; | 1459 s << endl << "};" << endl << endl; |
1371 } | 1460 } |
1372 | |
1373 writeQObjectEntity(s, java_class); | |
1374 } | 1461 } |
1375 | 1462 |
1376 | 1463 |
1377 void CppImplGenerator::writeShellConstructor(QTextStream &s, const AbstractMetaFunction *java_function) | 1464 void CppImplGenerator::writeShellConstructor(QTextStream &s, const AbstractMetaFunction *java_function) |
1378 { | 1465 { |
1932 else | 2019 else |
1933 s << "DArray " << arg_name; | 2020 s << "DArray " << arg_name; |
1934 } else if (d_type->isContainer()) { | 2021 } else if (d_type->isContainer()) { |
1935 const ContainerTypeEntry *cte = | 2022 const ContainerTypeEntry *cte = |
1936 static_cast<const ContainerTypeEntry *>(te); | 2023 static_cast<const ContainerTypeEntry *>(te); |
1937 if(isLinearContainer(cte)) | 2024 if(cte->isQList()) |
1938 s << QString("void *%1, size_t %1_size").arg(arg_name); | 2025 s << "void* " << arg_name; |
2026 else if(isLinearContainer(cte)) | |
2027 s << "DArray* " << arg_name; | |
1939 } else { | 2028 } else { |
1940 if (!d_type->hasNativeId()) { | 2029 if (!d_type->hasNativeId()) { |
1941 if(d_type->isVariant()) { | 2030 if(d_type->isVariant()) { |
1942 if (d_export) s << "void*"; | 2031 if (d_export) s << "void*"; |
1943 else s << "QVariant*"; | 2032 else s << "QVariant*"; |
2296 | 2385 |
2297 void CppImplGenerator::writeFinalDestructor(QTextStream &s, const AbstractMetaClass *cls) | 2386 void CppImplGenerator::writeFinalDestructor(QTextStream &s, const AbstractMetaClass *cls) |
2298 { | 2387 { |
2299 if (cls->hasConstructors()) { | 2388 if (cls->hasConstructors()) { |
2300 s << INDENT << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_destructor(void *ptr)" << endl | 2389 s << INDENT << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_destructor(void *ptr)" << endl |
2301 << INDENT << "{" << endl; | 2390 << INDENT << "{" << endl |
2302 { | 2391 << INDENT << " delete (" << shellClassName(cls) << " *)ptr;" << endl |
2303 s << INDENT << "delete (" << shellClassName(cls) << " *)ptr;" << endl; | 2392 << INDENT << "}" << endl << endl; |
2304 } | 2393 |
2305 | 2394 s << INDENT << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_call_destructor(" << shellClassName(cls) << " *ptr)" << endl |
2306 s << INDENT << "}" << endl << endl; | 2395 << INDENT << "{" << endl |
2396 << INDENT << " call_destructor(ptr);" << endl | |
2397 << INDENT << "}" << endl << endl; | |
2307 } | 2398 } |
2308 } | 2399 } |
2309 | 2400 |
2310 void CppImplGenerator::writeFinalConstructor(QTextStream &s, | 2401 void CppImplGenerator::writeFinalConstructor(QTextStream &s, |
2311 const AbstractMetaFunction *java_function, | 2402 const AbstractMetaFunction *java_function, |
2312 const QString &qt_object_name, | 2403 const QString &qt_object_name, |
2313 const QString &java_object_name) | 2404 const QString &java_object_name, |
2405 const QString &place) | |
2314 { | 2406 { |
2315 const AbstractMetaClass *cls = java_function->ownerClass(); | 2407 const AbstractMetaClass *cls = java_function->ownerClass(); |
2316 AbstractMetaArgumentList arguments = java_function->arguments(); | 2408 AbstractMetaArgumentList arguments = java_function->arguments(); |
2317 QString className = cls->typeEntry()->qualifiedCppName(); | 2409 QString className = cls->typeEntry()->qualifiedCppName(); |
2318 | 2410 |
2319 bool hasShellClass = cls->generateShellClass(); | 2411 bool hasShellClass = cls->generateShellClass(); |
2320 | 2412 |
2321 s << INDENT << shellClassName(cls) << " *" << qt_object_name | 2413 s << INDENT << shellClassName(cls) << " *" << qt_object_name |
2322 << " = new " << shellClassName(cls) | 2414 << " = new " << place << shellClassName(cls) |
2323 << "("; | 2415 << "("; |
2324 writeFunctionCallArguments(s, java_function, "__qt_"); | 2416 writeFunctionCallArguments(s, java_function, "__qt_"); |
2325 s << ");" << endl; | 2417 s << ");" << endl; |
2326 s << INDENT << "return (void *) " << qt_object_name << ";" << endl; // qtd | 2418 s << INDENT << "return (void *) " << qt_object_name << ";" << endl; // qtd |
2327 | 2419 |
3137 | 3229 |
3138 Q_ASSERT(java_type->isContainer()); | 3230 Q_ASSERT(java_type->isContainer()); |
3139 const ContainerTypeEntry *type = | 3231 const ContainerTypeEntry *type = |
3140 static_cast<const ContainerTypeEntry *>(java_type->typeEntry()); | 3232 static_cast<const ContainerTypeEntry *>(java_type->typeEntry()); |
3141 | 3233 |
3142 if (type->type() == ContainerTypeEntry::ListContainer | 3234 if (type->type() == ContainerTypeEntry::VectorContainer |
3143 || type->type() == ContainerTypeEntry::VectorContainer | |
3144 || type->type() == ContainerTypeEntry::StringListContainer | |
3145 || type->type() == ContainerTypeEntry::LinkedListContainer | 3235 || type->type() == ContainerTypeEntry::LinkedListContainer |
3146 || type->type() == ContainerTypeEntry::StackContainer | 3236 || type->type() == ContainerTypeEntry::StackContainer |
3147 || type->type() == ContainerTypeEntry::SetContainer | 3237 || type->type() == ContainerTypeEntry::SetContainer |
3148 || type->type() == ContainerTypeEntry::QueueContainer) { | 3238 || type->type() == ContainerTypeEntry::QueueContainer) { |
3149 | 3239 |
3152 | 3242 |
3153 QString cls_name = getTypeName(targ->typeEntry(), EnumAsInts); | 3243 QString cls_name = getTypeName(targ->typeEntry(), EnumAsInts); |
3154 cls_name.remove("_ConcreteWrapper"); | 3244 cls_name.remove("_ConcreteWrapper"); |
3155 | 3245 |
3156 s << endl | 3246 s << endl |
3157 // << INDENT << "{" << endl // qtd2 hack, additional scope for avoiding duplicating of "i" | |
3158 << INDENT; | 3247 << INDENT; |
3159 | 3248 |
3160 switch (type->type()) { | 3249 switch (type->type()) { |
3161 case ContainerTypeEntry::LinkedListContainer: | 3250 case ContainerTypeEntry::LinkedListContainer: |
3162 case ContainerTypeEntry::QueueContainer: | 3251 case ContainerTypeEntry::QueueContainer: |
3200 | 3289 |
3201 s << INDENT << "qtd_assign_" << cls_name << "_array_element(" << java_name << ", " << index << ", __java_tmp);" << endl; | 3290 s << INDENT << "qtd_assign_" << cls_name << "_array_element(" << java_name << ", " << index << ", __java_tmp);" << endl; |
3202 s << INDENT << "++" << index << ";" << endl; | 3291 s << INDENT << "++" << index << ";" << endl; |
3203 } | 3292 } |
3204 s << INDENT << "}" << endl; | 3293 s << INDENT << "}" << endl; |
3205 // << INDENT << "}" << endl; | 3294 |
3295 } else if (type->isQList()) { | |
3296 // QList<QObject*> & list2 = (*(QList<QObject*> *)nativeId); | |
3297 writeTypeInfo(s, java_type, ForceValueType); | |
3298 s << "&" << java_name << "_tmp = (*("; | |
3299 writeTypeInfo(s, java_type, ForceValueType); | |
3300 s << "*)" << java_name << ");" << endl | |
3301 << INDENT << java_name << "_tmp = " << qt_name << ";" << endl; | |
3206 | 3302 |
3207 } else if (type->type() == ContainerTypeEntry::PairContainer) { | 3303 } else if (type->type() == ContainerTypeEntry::PairContainer) { |
3208 QList<AbstractMetaType *> args = java_type->instantiations(); | 3304 QList<AbstractMetaType *> args = java_type->instantiations(); |
3209 Q_ASSERT(args.size() == 2); | 3305 Q_ASSERT(args.size() == 2); |
3210 | 3306 |
3327 | 3423 |
3328 Q_ASSERT(java_type->isContainer()); | 3424 Q_ASSERT(java_type->isContainer()); |
3329 const ContainerTypeEntry *type = | 3425 const ContainerTypeEntry *type = |
3330 static_cast<const ContainerTypeEntry *>(java_type->typeEntry()); | 3426 static_cast<const ContainerTypeEntry *>(java_type->typeEntry()); |
3331 | 3427 |
3332 if (type->type() == ContainerTypeEntry::ListContainer | 3428 if (type->type() == ContainerTypeEntry::VectorContainer |
3333 || type->type() == ContainerTypeEntry::VectorContainer | |
3334 || type->type() == ContainerTypeEntry::StringListContainer | |
3335 || type->type() == ContainerTypeEntry::LinkedListContainer | 3429 || type->type() == ContainerTypeEntry::LinkedListContainer |
3336 || type->type() == ContainerTypeEntry::StackContainer | 3430 || type->type() == ContainerTypeEntry::StackContainer |
3337 || type->type() == ContainerTypeEntry::SetContainer | 3431 || type->type() == ContainerTypeEntry::SetContainer |
3338 || type->type() == ContainerTypeEntry::QueueContainer) { | 3432 || type->type() == ContainerTypeEntry::QueueContainer) { |
3339 Q_ASSERT(java_type->instantiations().size() == 1); | 3433 Q_ASSERT(java_type->instantiations().size() == 1); |
3343 | 3437 |
3344 s << INDENT; | 3438 s << INDENT; |
3345 writeTypeInfo(s, java_type, ForceValueType); | 3439 writeTypeInfo(s, java_type, ForceValueType); |
3346 s << qt_name << ";" << endl; | 3440 s << qt_name << ";" << endl; |
3347 | 3441 |
3348 // qtd s << INDENT << "if (" << java_name << " != 0) {" << endl; | |
3349 { | 3442 { |
3350 /* qtd Indentation indent(INDENT); | |
3351 s << INDENT << "jobjectArray __qt__array = qtjambi_collection_toArray(__jni_env, " | |
3352 << java_name << ");" << endl | |
3353 << INDENT << "jsize __qt__size = __jni_env->GetArrayLength(__qt__array);" << endl; | |
3354 */ | |
3355 if (type->type() == ContainerTypeEntry::VectorContainer | 3443 if (type->type() == ContainerTypeEntry::VectorContainer |
3356 || type->type() == ContainerTypeEntry::StackContainer) | 3444 || type->type() == ContainerTypeEntry::StackContainer) |
3357 s << INDENT << qt_name << ".reserve(" << java_name << "_size);" << endl; | 3445 s << INDENT << qt_name << ".reserve(" << java_name << "->length);" << endl; |
3358 | 3446 |
3359 s << INDENT << "for (int i=0; i<" << java_name << "_size; ++i) {" << endl; | 3447 s << INDENT << "for (int i=0; i<" << java_name << "->length; ++i) {" << endl; |
3360 { | 3448 { |
3361 Indentation indent(INDENT); | 3449 Indentation indent(INDENT); |
3362 if(targ->isTargetLangString()) | 3450 if(targ->isTargetLangString()) |
3363 s << INDENT << "DArray __d_element;" << endl | 3451 s << INDENT << "DArray __d_element;" << endl |
3364 << INDENT << "qtd_get_string_from_array(" << java_name << ", i, &__d_element);" << endl; | 3452 << INDENT << "qtd_get_string_from_array(" << java_name << "->ptr, i, &__d_element);" << endl; |
3365 else { | 3453 else { |
3366 s << INDENT; | 3454 s << INDENT; |
3367 writeTypeInfo(s, targ, Option(VirtualDispatch | ForcePointer | EnumAsInts)); | 3455 writeTypeInfo(s, targ, Option(VirtualDispatch | ForcePointer | EnumAsInts)); |
3368 QString cast_string = ""; | 3456 QString cast_string = ""; |
3369 const TypeEntry* centry = targ->typeEntry(); | 3457 const TypeEntry* centry = targ->typeEntry(); |
3370 if (centry->isComplex() && (centry->isObject() || centry->isValue() || centry->isInterface())) | 3458 if (centry->isComplex() && (centry->isObject() || centry->isValue() || centry->isInterface())) |
3371 cast_string = "(void**)"; | 3459 cast_string = "(void**)"; |
3372 s << "__d_element;" << endl | 3460 s << "__d_element;" << endl |
3373 << INDENT << "qtd_get_" << elem_type << "_from_array(" << java_name << ", i, &__d_element);" << endl; | 3461 << INDENT << "qtd_get_" << elem_type << "_from_array(" << java_name << ", i, &__d_element);" << endl; |
3374 } | 3462 } |
3375 /* qtd s << INDENT << "jobject __d_element = " | |
3376 << "__jni_env->GetObjectArrayElement(__qt__array, i);" << endl;*/ | |
3377 writeJavaToQt(s, targ, "__qt_element", "__d_element", 0, -1, BoxedPrimitive); | 3463 writeJavaToQt(s, targ, "__qt_element", "__d_element", 0, -1, BoxedPrimitive); |
3378 QString cont_element = "__qt_element"; | 3464 QString cont_element = "__qt_element"; |
3379 if(targ->typeEntry()->isStructInD() && targ->name() != "QModelIndex") | 3465 if(targ->typeEntry()->isStructInD() && targ->name() != "QModelIndex") |
3380 cont_element = "__d_element"; | 3466 cont_element = "__d_element"; |
3381 s << INDENT << qt_name << " << " << cont_element << ";" << endl; | 3467 s << INDENT << qt_name << " << " << cont_element << ";" << endl; |
3382 } | 3468 } |
3383 // qtd s << INDENT << "}" << endl; | 3469 // qtd s << INDENT << "}" << endl; |
3384 } | 3470 } |
3385 s << INDENT << "}" << endl; | 3471 s << INDENT << "}" << endl; |
3472 } else if (type->isQList()) { | |
3473 writeTypeInfo(s, java_type, ForceValueType); | |
3474 s << qt_name << " = (*("; | |
3475 writeTypeInfo(s, java_type, ForceValueType); | |
3476 s << "*)" << java_name << ");" << endl; | |
3386 } else if (type->type() == ContainerTypeEntry::PairContainer) { | 3477 } else if (type->type() == ContainerTypeEntry::PairContainer) { |
3387 QList<AbstractMetaType *> targs = java_type->instantiations(); | 3478 QList<AbstractMetaType *> targs = java_type->instantiations(); |
3388 Q_ASSERT(targs.size() == 2); | 3479 Q_ASSERT(targs.size() == 2); |
3389 | 3480 |
3390 s << INDENT; | 3481 s << INDENT; |
3546 } | 3637 } |
3547 } | 3638 } |
3548 | 3639 |
3549 if ( (options & VirtualDispatch) | 3640 if ( (options & VirtualDispatch) |
3550 && a_type->isContainer()) { | 3641 && a_type->isContainer()) { |
3551 s << "__d_" << argument->indexedName(); | 3642 if ( ((const ContainerTypeEntry *)a_type->typeEntry())->isQList() ) |
3643 s << "(void*)&" << argument->indexedName(); | |
3644 else | |
3645 s << "__d_" << argument->indexedName(); | |
3552 continue; | 3646 continue; |
3553 } | 3647 } |
3554 | 3648 |
3555 if ((!(options & NoCasts) && !enum_as_int) || ((options & ForceEnumCast) && a_type->isEnum())) { | 3649 if ((!(options & NoCasts) && !enum_as_int) || ((options & ForceEnumCast) && a_type->isEnum())) { |
3556 | 3650 |
3720 << ");" << endl; | 3814 << ");" << endl; |
3721 } | 3815 } |
3722 s << endl << endl; | 3816 s << endl << endl; |
3723 } | 3817 } |
3724 } | 3818 } |
3819 |