comparison generator/cppimplgenerator.cpp @ 253:073b9153ed8a

Rev. 264 done right. Problems: - classwizard segfaults on exit due to a bug in signals/slots or runtime. - hellogl doesn't compile with dmd2 due to a bug in the compiler backend
author maxter
date Sun, 30 Aug 2009 09:59:12 +0000
parents 37eed70de029
children 17b5e13364b7 49bfc86ff583
comparison
equal deleted inserted replaced
252:37eed70de029 253:073b9153ed8a
463 bool CppImplGenerator::hasCustomDestructor(const AbstractMetaClass *java_class) const 463 bool CppImplGenerator::hasCustomDestructor(const AbstractMetaClass *java_class) const
464 { 464 {
465 return !java_class->isQObject() && !java_class->typeEntry()->isValue(); 465 return !java_class->isQObject() && !java_class->typeEntry()->isValue();
466 } 466 }
467 467
468 void writeQtdEntityFunction(QTextStream &s, const AbstractMetaClass *java_class)
469 {
470 // if (!(java_class->typeEntry()->isObject() || java_class->typeEntry()->isQObject()))
471 // return;
472 if (!java_class->hasVirtualFunctions())
473 return;
474
475 s << "extern \"C\" DLL_PUBLIC void *__" << java_class->name() << "_entity(void *q_ptr)" << endl;
476 s << "{" << endl;
477 {
478 Indentation indent(INDENT);
479 s << INDENT << "Qtd_QObjectEntity* a = dynamic_cast<Qtd_QObjectEntity*>((" << java_class->qualifiedCppName() << "*)q_ptr);" << endl
480 << INDENT << "if (a != NULL)" << endl
481 << INDENT << " return a->d_entity();" << endl
482 << INDENT << "else" << endl
483 << INDENT << " return NULL;" << endl;
484 }
485 s << "}" << endl << endl;
486 }
487
488 void CppImplGenerator::writeInterfaceCasts(QTextStream &s, const AbstractMetaClass *java_class) 468 void CppImplGenerator::writeInterfaceCasts(QTextStream &s, const AbstractMetaClass *java_class)
489 { 469 {
490 // pointers to native interface objects for classes that implement interfaces 470 // pointers to native interface objects for classes that implement interfaces
491 // initializing 471 // initializing
492 AbstractMetaClassList interfaces = java_class->interfaces(); 472 AbstractMetaClassList interfaces = java_class->interfaces();
529 // D-side signal callbacks 509 // D-side signal callbacks
530 AbstractMetaFunctionList signal_funcs = signalFunctions(java_class); 510 AbstractMetaFunctionList signal_funcs = signalFunctions(java_class);
531 for(int i = 0; i < signal_funcs.size(); i++) 511 for(int i = 0; i < signal_funcs.size(); i++)
532 s << " emit_callbacks_" << java_class->name() << "[" << i << "] = (EmitCallback)" 512 s << " emit_callbacks_" << java_class->name() << "[" << i << "] = (EmitCallback)"
533 "sigs[" << i << "];" << endl; 513 "sigs[" << i << "];" << endl;
534
535 if (java_class->isQObject())
536 s << " qtd_D_" << java_class->name() << "_delete = "
537 "(qtd_pf_D_" << java_class->name() << "_delete)qobj_del;" << endl;
538
539 514
540 s << "}" << endl; 515 s << "}" << endl;
541 } 516 }
542 517
543 518
569 s << "#include \"" << java_class->name() << "_shell" << ".h\"" << endl; 544 s << "#include \"" << java_class->name() << "_shell" << ".h\"" << endl;
570 /* qtd 545 /* qtd
571 if (java_class->isQObject()) 546 if (java_class->isQObject())
572 s << "#include <qtdynamicmetaobject.h>" << endl; 547 s << "#include <qtdynamicmetaobject.h>" << endl;
573 */ 548 */
549 if (java_class->isQObject())
550 s << "#include <QObjectEntity.h>" << endl;
551
574 s << "#include <iostream>" << endl; 552 s << "#include <iostream>" << endl;
553
554
555
575 Include inc = java_class->typeEntry()->include(); 556 Include inc = java_class->typeEntry()->include();
576 if (!inc.name.isEmpty()) { 557 if (!inc.name.isEmpty()) {
577 s << "#include "; 558 s << "#include ";
578 if (inc.type == Include::IncludePath) 559 if (inc.type == Include::IncludePath)
579 s << "<"; 560 s << "<";
606 writeShellSignatures(s, java_class); 587 writeShellSignatures(s, java_class);
607 588
608 writeDefaultConstructedValues(s, java_class); 589 writeDefaultConstructedValues(s, java_class);
609 590
610 if (hasCustomDestructor(java_class)) */ 591 if (hasCustomDestructor(java_class)) */
611 writeFinalDestructor(s, java_class); 592 if (!java_class->isQObject())
593 writeFinalDestructor(s, java_class);
612 594
613 if (java_class->isQObject()) 595 if (java_class->isQObject())
614 writeSignalsHandling(s, java_class); 596 writeSignalsHandling(s, java_class);
615 597
616 if (shellClass) { 598 if (shellClass) {
618 if (function->isConstructor() && !function->isPrivate()) 600 if (function->isConstructor() && !function->isPrivate())
619 writeShellConstructor(s, function); 601 writeShellConstructor(s, function);
620 } 602 }
621 writeShellDestructor(s, java_class); 603 writeShellDestructor(s, java_class);
622 604
623 writeQtdEntityFunction(s, java_class); 605 if (!java_class->isQObject() && java_class->hasVirtualFunctions())
606 writeQtdEntityFunction(s, java_class);
624 607
625 if (java_class->isQObject()) 608 if (java_class->isQObject())
626 writeQObjectFunctions(s, java_class); 609 writeQObjectFunctions(s, java_class);
627 610
628 // Virtual overrides 611 // Virtual overrides
720 } 703 }
721 704
722 writeSignalInitialization(s, java_class); 705 writeSignalInitialization(s, java_class);
723 */ 706 */
724 // qtd writeJavaLangObjectOverrideFunctions(s, java_class); 707 // qtd writeJavaLangObjectOverrideFunctions(s, java_class);
708
709 if (java_class->isQObject())
710 {
711 s << endl << endl
712 << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_staticMetaObject() {" << endl
713 << " return (void*)&" << java_class->name() << "::staticMetaObject;" << endl
714 << "}" << endl;
715 }
725 716
726 s << endl << endl; 717 s << endl << endl;
727 718
728 priGenerator->addSource(java_class->package(), fileNameForClass(java_class)); 719 priGenerator->addSource(java_class->package(), fileNameForClass(java_class));
729 } 720 }
836 if (f_type->isEnum() || f_type->isFlags()) 827 if (f_type->isEnum() || f_type->isFlags())
837 s << "(" << f_type->typeEntry()->qualifiedCppName() <<") "; 828 s << "(" << f_type->typeEntry()->qualifiedCppName() <<") ";
838 } 829 }
839 830
840 s << function->marshalledName() << "_dispatch(" 831 s << function->marshalledName() << "_dispatch("
841 << "this->d_entity()"; 832 << "this->dId";
842 833
843 if (f_type) { 834 if (f_type) {
844 if (f_type->isTargetLangString()) 835 if (f_type->isTargetLangString())
845 s << ", &ret_str"; 836 s << ", &ret_str";
846 if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) 837 if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD())
859 850
860 if (f_type) { 851 if (f_type) {
861 if (f_type->name() == "QModelIndex") { 852 if (f_type->name() == "QModelIndex") {
862 s << INDENT << "QModelIndex __qt_return_value = qtd_to_QModelIndex( __d_return_value );" << endl; 853 s << INDENT << "QModelIndex __qt_return_value = qtd_to_QModelIndex( __d_return_value );" << endl;
863 #ifdef Q_OS_WIN32 854 #ifdef Q_OS_WIN32
864 s << "__qtd_dummy();" << endl; // hack!!! 855 s << "qtd_dummy();" << endl; // hack!!!
865 #endif 856 #endif
866 s << INDENT << "return __qt_return_value;" << endl; 857 s << INDENT << "return __qt_return_value;" << endl;
867 } else if (f_type->typeEntry()->isStructInD()) 858 } else if (f_type->typeEntry()->isStructInD())
868 s << INDENT << "return __d_return_value;" << endl; 859 s << INDENT << "return __d_return_value;" << endl;
869 860
1212 s << "static const int qtjambi_signal_count = " << signal_functions.size() << ";" << endl 1203 s << "static const int qtjambi_signal_count = " << signal_functions.size() << ";" << endl
1213 << endl; 1204 << endl;
1214 } 1205 }
1215 } 1206 }
1216 1207
1208 void CppImplGenerator::writeQObjectEntity(QTextStream &s, const AbstractMetaClass *java_class)
1209 {
1210 QString entityName = java_class->name() + "Entity";
1211 QString className = java_class->name();
1212
1213 s << "class " << entityName << " : public QObject, public QtD_QObjectEntity" << endl
1214 << "{" << endl
1215 << "public:" << endl
1216 << " Q_OBJECT_CHECK" << endl
1217 << " virtual int qt_metacall(QMetaObject::Call, int, void **);" << endl << endl
1218
1219 << " " << entityName << "(QObject *qObject, void *dId) : QObject(), QtD_QObjectEntity(qObject, dId) {}" << endl
1220 << "};" << endl << endl;
1221
1222 // QObject_Link::qt_metacall()
1223 s << "int " << entityName << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl
1224 << "{" << endl
1225 << " _id = QObject::qt_metacall(_c, _id, _a);" << endl
1226 << " if (_id < 0 || _c != QMetaObject::InvokeMetaMethod)" << endl
1227 << " return _id;" << endl
1228 // << " Q_ASSERT(_id < 2);" << endl
1229 << " emit_callbacks_" << java_class->name() << "[_id](dId, _a);" << endl
1230 << " return -1;" << endl
1231 << "}" << endl << endl;
1232
1233 s << "extern \"C\" DLL_PUBLIC void qtd_" << className << "_createEntity(void *nativeId, void* dId)" << endl
1234 << "{" << endl
1235 << " new " << entityName << "((QObject*)nativeId, dId);" << endl
1236 << "}" << endl << endl;
1237 }
1238
1217 void CppImplGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *java_class) 1239 void CppImplGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *java_class)
1218 { 1240 {
1219 // QObject::metaObject() 1241 // QObject::metaObject()
1220 /* s << "const QMetaObject *" << shellClassName(java_class) << "::metaObject() const" << endl 1242 /* s << "const QMetaObject *" << shellClassName(java_class) << "::metaObject() const" << endl
1221 << "{" << endl 1243 << "{" << endl
1255 << " if (!strcmp(_clname, \"" << shellClassName(java_class) << "\"))" << endl 1277 << " if (!strcmp(_clname, \"" << shellClassName(java_class) << "\"))" << endl
1256 << " return static_cast<void*>(const_cast<" << shellClassName(java_class) << "*>(this));" << endl 1278 << " return static_cast<void*>(const_cast<" << shellClassName(java_class) << "*>(this));" << endl
1257 << " return " << java_class->qualifiedCppName() << "::qt_metacast(_clname);" << endl 1279 << " return " << java_class->qualifiedCppName() << "::qt_metacast(_clname);" << endl
1258 << "}" << endl << endl; 1280 << "}" << endl << endl;
1259 */ 1281 */
1260 1282
1261 // writeSignalsHandling(s, java_class);
1262 /*
1263 // QObject_Link::qt_metacall()
1264 s << "int " << shellClassName(java_class) << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl 1283 s << "int " << shellClassName(java_class) << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl
1265 << "{" << endl; 1284 << "{" << endl;
1266 1285
1267 s << " _id = " << java_class->qualifiedCppName() << "::qt_metacall(_c, _id, _a);" << endl 1286 s << " _id = " << java_class->qualifiedCppName() << "::qt_metacall(_c, _id, _a);" << endl
1268 << " if (_id < 0 || _c != QMetaObject::InvokeMetaMethod)" << endl 1287 << " if (_id < 0 || _c != QMetaObject::InvokeMetaMethod)" << endl
1269 << " return _id;" << endl 1288 << " return _id;" << endl
1270 // << " Q_ASSERT(_id < 2);" << endl 1289 << " emit_callbacks_" << java_class->name() << "[_id](this->dId, _a);" << endl
1271 << " emit_callbacks_" << java_class->name() << "[_id](this->d_entity(), _a);" << endl
1272 << " return -1;" << endl 1290 << " return -1;" << endl
1273 << "}" << endl << endl; 1291 << "}" << endl << endl;
1274 */
1275 } 1292 }
1276 1293
1277 void CppImplGenerator::writeSignalHandler(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunction *function) 1294 void CppImplGenerator::writeSignalHandler(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunction *function)
1278 { 1295 {
1279 QString extra_args, extra_call_args, conversion_code; 1296 QString extra_args, extra_call_args, conversion_code;
1312 << "{" << endl 1329 << "{" << endl
1313 << conversion_code << endl 1330 << conversion_code << endl
1314 << INDENT << sig_name << "_handle_in_d(d_entity, args" << extra_call_args << ");" << endl 1331 << INDENT << sig_name << "_handle_in_d(d_entity, args" << extra_call_args << ");" << endl
1315 << "}" << endl; 1332 << "}" << endl;
1316 1333
1317 }
1318
1319 void CppImplGenerator::writeQObjectLink(QTextStream &s, const AbstractMetaClass *java_class)
1320 {
1321 QString linkName = java_class->name() + "_Link";
1322 QString className = java_class->name();
1323
1324 if (cpp_shared)
1325 s << "extern \"C\" typedef void (*qtd_pf_D_" << java_class->name() << "_delete)(void *d_ptr);" << endl
1326 << "qtd_pf_D_" << java_class->name() << "_delete qtd_D_" << java_class->name() << "_delete;" << endl << endl;
1327 else
1328 s << "extern \"C\" void qtd_D_" << java_class->name() << "_delete(void *d_ptr);" << endl << endl;
1329
1330 s << "class " << linkName << " : public QObject, public QObjectUserData" << endl
1331 << "{" << endl
1332 << "public:" << endl
1333 << " Q_OBJECT_CHECK" << endl
1334 << " virtual int qt_metacall(QMetaObject::Call, int, void **);" << endl << endl
1335
1336 << " " << linkName << "(QObject *parent, void *d_ptr) : QObject() { _d_ptr = d_ptr; }" << endl
1337 << " ~" << linkName << "() { qtd_D_" << className << "_delete(_d_ptr); }" << endl
1338 << " void *d_entity() const { return _d_ptr; }" << endl << endl
1339
1340 << "private:" << endl
1341 << " void *_d_ptr;" << endl
1342 << "};" << endl << endl;
1343
1344 // QObject_Link::qt_metacall()
1345 s << "int " << linkName << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl
1346 << "{" << endl
1347 << " _id = QObject::qt_metacall(_c, _id, _a);" << endl
1348 << " if (_id < 0 || _c != QMetaObject::InvokeMetaMethod)" << endl
1349 << " return _id;" << endl
1350 // << " Q_ASSERT(_id < 2);" << endl
1351 << " emit_callbacks_" << java_class->name() << "[_id](this->d_entity(), _a);" << endl
1352 << " return -1;" << endl
1353 << "}" << endl << endl;
1354
1355 s << QString("inline %1_Link *get_%1_link(%1 *obj)").arg(className) << endl
1356 << "{" << endl
1357 << " return static_cast<" << linkName << "*>(obj->userData(USER_DATA_ID));" << endl
1358 << "}" << endl << endl;
1359
1360 s << QString("extern \"C\" DLL_PUBLIC void* qtd_%1_d_pointer(%1 *obj)").arg(className) << endl
1361 << "{" << endl
1362 << " if (obj->userData(USER_DATA_ID)) {" << endl
1363 << " " << QString("%1_Link *qobj_helper = get_%1_link(obj);").arg(className) << endl
1364 << " return qobj_helper->d_entity();" << endl
1365 << " } else" << endl
1366 << " return NULL;" << endl
1367 << "}" << endl << endl;
1368
1369 s << QString("extern \"C\" DLL_PUBLIC void qtd_%1_create_link(%1 *obj, void* d_obj)").arg(className) << endl
1370 << "{" << endl
1371 << " if(obj->userData(USER_DATA_ID))" << endl
1372 << " return;" << endl
1373 << " " << QString("%1 *qobj_link = new %1(obj, d_obj);").arg(linkName) << endl
1374 << " obj->setUserData(USER_DATA_ID, qobj_link);" << endl
1375 << "}" << endl << endl;
1376 } 1334 }
1377 1335
1378 void CppImplGenerator::writeSignalsHandling(QTextStream &s, const AbstractMetaClass *java_class) 1336 void CppImplGenerator::writeSignalsHandling(QTextStream &s, const AbstractMetaClass *java_class)
1379 { 1337 {
1380 s << "extern \"C\" typedef void (*EmitCallback)(void*, void**);" << endl; 1338 s << "extern \"C\" typedef void (*EmitCallback)(void*, void**);" << endl;
1404 s << "&" << signalExternName(java_class, signal) << "_handle"; 1362 s << "&" << signalExternName(java_class, signal) << "_handle";
1405 } 1363 }
1406 s << endl << "};" << endl << endl; 1364 s << endl << "};" << endl << endl;
1407 } 1365 }
1408 1366
1409 writeQObjectLink(s, java_class); 1367 writeQObjectEntity(s, java_class);
1410
1411 // Functions connecting/disconnecting shell's slots
1412 for(int i = 0; i < signal_funcs.size(); i++) {
1413 AbstractMetaFunction *signal = signal_funcs.at(i);
1414 QString sigExternName = signalExternName(java_class, signal);
1415
1416 s << "extern \"C\" DLL_PUBLIC void " << sigExternName << "_connect"
1417 << "(void* native_id)" << endl << "{" << endl
1418 << " " << shellClassName(java_class) << " *qobj = (" << shellClassName(java_class) << "*) native_id;" << endl
1419 << " const QMetaObject &mo = " << java_class->name() << "::staticMetaObject;" << endl
1420 << " const QMetaObject &mo2 = " << java_class->name() << "_Link::staticMetaObject;" << endl
1421 << " int signalId = mo.indexOfSignal(\"" << signal->minimalSignature() << "\");" << endl
1422 << " mo.connect(qobj, signalId, get_" << java_class->name() << "_link(qobj), mo2.methodCount() + " << i << ");" << endl
1423 << "}" << endl;
1424
1425 s << "extern \"C\" DLL_PUBLIC void " << sigExternName << "_disconnect"
1426 << "(void* native_id)" << endl << "{" << endl
1427 << " " << shellClassName(java_class) << " *qobj = (" << shellClassName(java_class) << "*) native_id;" << endl
1428 << " const QMetaObject &mo = " << shellClassName(java_class) << "::staticMetaObject;" << endl
1429 << " const QMetaObject &mo2 = " << java_class->name() << "_Link::staticMetaObject;" << endl
1430 << " int signalId = mo.indexOfSignal(\"" << signal->minimalSignature() << "\");" << endl
1431 << " mo.disconnect(qobj, signalId, get_" << java_class->name() << "_link(qobj), mo2.methodCount() + " << i << ");" << endl
1432 << "}" << endl << endl;
1433 }
1434 } 1368 }
1435 1369
1436 1370
1437 void CppImplGenerator::writeShellConstructor(QTextStream &s, const AbstractMetaFunction *java_function) 1371 void CppImplGenerator::writeShellConstructor(QTextStream &s, const AbstractMetaFunction *java_function)
1438 { 1372 {
1450 s << arguments.at(i)->indexedName(); 1384 s << arguments.at(i)->indexedName();
1451 if (i != arguments.size() - 1) 1385 if (i != arguments.size() - 1)
1452 s << ", "; 1386 s << ", ";
1453 } 1387 }
1454 s << ")"; 1388 s << ")";
1455 if (cls->hasVirtualFunctions()) 1389 if (cls->isQObject())
1456 s << "," << endl << " Qtd_QObjectEntity(d_ptr)"; 1390 s << "," << endl << " QtD_QObjectEntity(this, d_ptr)";
1391 else if (cls->hasVirtualFunctions())
1392 s << "," << endl << " QtD_Entity(d_ptr)";
1457 /* qtd s << " m_meta_object(0)," << endl; 1393 /* qtd s << " m_meta_object(0)," << endl;
1458 s << " m_vtable(0)," << endl 1394 s << " m_vtable(0)," << endl
1459 << " m_link(0)" << endl; 1395 << " m_link(0)" << endl;
1460 */ 1396 */
1461 s << endl; 1397 s << endl;
1462 s << "{" << endl; 1398 s << "{" << endl;
1463 { 1399 {
1464 Indentation indent(INDENT); 1400 Indentation indent(INDENT);
1401
1465 writeCodeInjections(s, java_function, cls, CodeSnip::Beginning, TypeSystem::ShellCode); 1402 writeCodeInjections(s, java_function, cls, CodeSnip::Beginning, TypeSystem::ShellCode);
1466 writeCodeInjections(s, java_function, cls, CodeSnip::End, TypeSystem::ShellCode); 1403 writeCodeInjections(s, java_function, cls, CodeSnip::End, TypeSystem::ShellCode);
1467 } 1404 }
1468 s << "}" << endl << endl; 1405 s << "}" << endl << endl;
1469 } 1406 }
1472 { 1409 {
1473 s << shellClassName(java_class) << "::~" 1410 s << shellClassName(java_class) << "::~"
1474 << shellClassName(java_class) << "()" << endl 1411 << shellClassName(java_class) << "()" << endl
1475 << "{" << endl; 1412 << "{" << endl;
1476 { 1413 {
1477 /* qtd 1414 //s << " std::cout << \"In shell destructor of " << java_class->name() << ", nativeId: \" << this << std::endl;";
1478 Indentation indent(INDENT); 1415 if (java_class->isQObject())
1479 1416 s << " destroyEntity(this);";
1480 s << "#ifdef QT_DEBUG" << endl
1481 << INDENT << "if (m_vtable)" << endl
1482 << INDENT << " m_vtable->deref();" << endl
1483 << "#endif" << endl
1484 << INDENT << "if (m_link) {" << endl;
1485
1486 AbstractMetaClassList interfaces = java_class->interfaces();
1487 if (interfaces.size() + (java_class->baseClass() != 0 ? 1 : 0) > 1) {
1488 if (java_class->baseClass() != 0)
1489 interfaces += java_class->baseClass();
1490 foreach (AbstractMetaClass *iface, interfaces) {
1491 AbstractMetaClass *impl = iface->isInterface() ? iface->primaryInterfaceImplementor() : iface;
1492 s << INDENT << " m_link->unregisterSubObject((" << impl->qualifiedCppName() << " *) this);" << endl;
1493 }
1494 }
1495
1496 if (!java_class->isQObject()) {
1497 s << INDENT << " JNIEnv *__jni_env = qtjambi_current_environment();" << endl
1498 << INDENT << " if (__jni_env != 0) m_link->nativeShellObjectDestroyed(__jni_env);" << endl;
1499 }
1500
1501 #if defined(QTJAMBI_DEBUG_TOOLS)
1502 s << INDENT << " qtjambi_increase_shellDestructorCalledCount(QString::fromLatin1(\"" << java_class->name() << "\"));" << endl;
1503 #endif
1504
1505 s << INDENT << "}" << endl; */
1506 } 1417 }
1507 s << "}" << endl << endl; 1418 s << "}" << endl << endl;
1508 } 1419 }
1509 1420
1510 void CppImplGenerator::writeCodeInjections(QTextStream &s, const AbstractMetaFunction *java_function, 1421 void CppImplGenerator::writeCodeInjections(QTextStream &s, const AbstractMetaFunction *java_function,
1816 Indentation indent(INDENT); 1727 Indentation indent(INDENT);
1817 writeBaseClassFunctionCall(s, java_function, implementor); 1728 writeBaseClassFunctionCall(s, java_function, implementor);
1818 s << "}" << endl << endl; 1729 s << "}" << endl << endl;
1819 } 1730 }
1820 1731
1732 void CppImplGenerator::writeQtdEntityFunction(QTextStream &s, const AbstractMetaClass *java_class)
1733 {
1734 s << "extern \"C\" DLL_PUBLIC void *__" << java_class->name() << "_entity(void *q_ptr)" << endl;
1735 s << "{" << endl;
1736 {
1737 Indentation indent(INDENT);
1738 s << INDENT << "QtD_Entity* a = dynamic_cast<QtD_Entity*>((" << java_class->qualifiedCppName() << "*)q_ptr);" << endl
1739 << INDENT << "if (a != NULL)" << endl
1740 << INDENT << " return a->dId;" << endl
1741 << INDENT << "else" << endl
1742 << INDENT << " return NULL;" << endl;
1743 }
1744 s << "}" << endl << endl;
1745 }
1821 1746
1822 void CppImplGenerator::writeVirtualFunctionOverride(QTextStream &s, 1747 void CppImplGenerator::writeVirtualFunctionOverride(QTextStream &s,
1823 const AbstractMetaFunction *java_function, 1748 const AbstractMetaFunction *java_function,
1824 const AbstractMetaClass *implementor) 1749 const AbstractMetaClass *implementor)
1825 { 1750 {
2154 function_prefix = "__public_"; 2079 function_prefix = "__public_";
2155 } else if (!java_function->isFinalInCpp() && !java_function->isStatic() && hasShell) { 2080 } else if (!java_function->isFinalInCpp() && !java_function->isStatic() && hasShell) {
2156 function_prefix = "__override_"; 2081 function_prefix = "__override_";
2157 extra_param.append("__do_static_call"); 2082 extra_param.append("__do_static_call");
2158 s << INDENT 2083 s << INDENT
2159 << "bool __do_static_call = __this_nativeId ? " 2084 << "bool __do_static_call = __this_nativeId ? ";
2160 << "__" << java_class->name() << "_entity(__this_nativeId) : false;" << endl; 2085 if (java_class->isQObject())
2086 s << "QtD_QObjectEntity::getQObjectEntity((QObject*)__this_nativeId) : false;" << endl;
2087 else
2088 s << "__" << java_class->name() << "_entity(__this_nativeId) : false;" << endl;
2161 } else { 2089 } else {
2162 option = OriginalName; 2090 option = OriginalName;
2163 } 2091 }
2164 2092
2165 // Call the Qt function on the java object 2093 // Call the Qt function on the java object
2212 AbstractMetaArgumentList arguments = java_function->arguments(); 2140 AbstractMetaArgumentList arguments = java_function->arguments();
2213 foreach (const AbstractMetaArgument *argument, arguments) { 2141 foreach (const AbstractMetaArgument *argument, arguments) {
2214 AbstractMetaType *d_type = argument->type(); 2142 AbstractMetaType *d_type = argument->type();
2215 const TypeEntry *te = d_type->typeEntry(); 2143 const TypeEntry *te = d_type->typeEntry();
2216 if ((te && d_type->isNativePointer() && te->name() == "QString")) 2144 if ((te && d_type->isNativePointer() && te->name() == "QString"))
2217 s << QString(" _d_toUtf8(__qt_%1.utf16(), __qt_%1.size(), &%1);").arg(argument->indexedName()) << endl; 2145 s << QString(" qtd_toUtf8(__qt_%1.utf16(), __qt_%1.size(), &%1);").arg(argument->indexedName()) << endl;
2218 } 2146 }
2219 } 2147 }
2220 2148
2221 void CppImplGenerator::writeAssignment(QTextStream &s, const QString &destName, const QString &srcName, 2149 void CppImplGenerator::writeAssignment(QTextStream &s, const QString &destName, const QString &srcName,
2222 const AbstractMetaType *java_type) 2150 const AbstractMetaType *java_type)
2364 { 2292 {
2365 if (cls->hasConstructors()) { 2293 if (cls->hasConstructors()) {
2366 s << INDENT << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_destructor(void *ptr)" << endl 2294 s << INDENT << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_destructor(void *ptr)" << endl
2367 << INDENT << "{" << endl; 2295 << INDENT << "{" << endl;
2368 { 2296 {
2369 Indentation indent(INDENT);
2370 /* qtd
2371 if (!cls->isQObject() && !cls->generateShellClass()) {
2372 s << INDENT << "QtJambiLink *link = QtJambiLink::findLinkForUserObject(ptr);" << endl
2373 << INDENT << "if (link) link->resetObject(qtjambi_current_environment());" << endl;
2374 }
2375
2376 // Code injectsions...
2377 foreach (const CodeSnip &snip, cls->typeEntry()->codeSnips()) {
2378 if (snip.language == TypeSystem::DestructorFunction) {
2379 s << snip.code();
2380 }
2381 }
2382 */
2383 s << INDENT << "delete (" << shellClassName(cls) << " *)ptr;" << endl; 2297 s << INDENT << "delete (" << shellClassName(cls) << " *)ptr;" << endl;
2384
2385 #if defined(QTJAMBI_DEBUG_TOOLS)
2386 s << INDENT << "qtjambi_increase_destructorFunctionCalledCount(QString::fromLatin1(\"" << cls->name() << "\"));" << endl;
2387 #endif
2388 } 2298 }
2389 2299
2390 s << INDENT << "}" << endl << endl; 2300 s << INDENT << "}" << endl << endl;
2391 } 2301 }
2392 } 2302 }
3078 << " = new QVariant(" << qt_name << ");" << endl; 2988 << " = new QVariant(" << qt_name << ");" << endl;
3079 } else if (java_type->isTargetLangString()) { 2989 } else if (java_type->isTargetLangString()) {
3080 if(java_type->typeEntry()->qualifiedCppName() == "QStringRef") { 2990 if(java_type->typeEntry()->qualifiedCppName() == "QStringRef") {
3081 s << INDENT << "const QString *str_ref = " << qt_name << ".string();" << endl 2991 s << INDENT << "const QString *str_ref = " << qt_name << ".string();" << endl
3082 << INDENT << "if(str_ref)" << endl 2992 << INDENT << "if(str_ref)" << endl
3083 << INDENT << " _d_toUtf8(str_ref->utf16(), str_ref->size(), " << java_name << ");" << endl 2993 << INDENT << " qtd_toUtf8(str_ref->utf16(), str_ref->size(), " << java_name << ");" << endl
3084 << INDENT << "else {" << endl 2994 << INDENT << "else {" << endl
3085 << INDENT << " QString empty_str;" << endl 2995 << INDENT << " QString empty_str;" << endl
3086 << INDENT << " _d_toUtf8(empty_str.utf16(), empty_str.size(), " << java_name << ");" << endl 2996 << INDENT << " qtd_toUtf8(empty_str.utf16(), empty_str.size(), " << java_name << ");" << endl
3087 << INDENT << "}" << endl; 2997 << INDENT << "}" << endl;
3088 } else { 2998 } else {
3089 s << INDENT << QString("_d_toUtf8(%1.utf16(), %1.size(), %2);").arg(qt_name, java_name) << endl; 2999 s << INDENT << QString("qtd_toUtf8(%1.utf16(), %1.size(), %2);").arg(qt_name, java_name) << endl;
3090 } 3000 }
3091 } else if (java_type->isTargetLangChar()) { 3001 } else if (java_type->isTargetLangChar()) {
3092 s << INDENT << "jchar " << java_name << " = " << qt_name << ".unicode();" << endl; 3002 s << INDENT << "jchar " << java_name << " = " << qt_name << ".unicode();" << endl;
3093 3003
3094 } else if (java_type->isIntegerEnum() || java_type->isIntegerFlags() 3004 } else if (java_type->isIntegerEnum() || java_type->isIntegerFlags()