Mercurial > projects > qtd
comparison generator/cppimplgenerator.cpp @ 257:17b5e13364b7 lifetime
(none)
author | maxter |
---|---|
date | Wed, 16 Sep 2009 13:56:02 +0000 |
parents | 073b9153ed8a |
children | 515d6e1c7b10 |
comparison
equal
deleted
inserted
replaced
256:b1abe7f57321 | 257:17b5e13364b7 |
---|---|
539 #if defined(QTJAMBI_DEBUG_TOOLS) | 539 #if defined(QTJAMBI_DEBUG_TOOLS) |
540 s << "#include <qtjambidebugtools_p.h>" << endl << endl; | 540 s << "#include <qtjambidebugtools_p.h>" << endl << endl; |
541 #endif | 541 #endif |
542 */ | 542 */ |
543 if (shellInclude) | 543 if (shellInclude) |
544 s << "#include \"" << java_class->name() << "_shell" << ".h\"" << endl; | 544 { |
545 s << "#include \"" << java_class->name() << "_shell" << ".h\"" << endl | |
546 << "#include <typeinfo>" << endl; | |
547 } | |
548 | |
545 /* qtd | 549 /* qtd |
546 if (java_class->isQObject()) | 550 if (java_class->isQObject()) |
547 s << "#include <qtdynamicmetaobject.h>" << endl; | 551 s << "#include <qtdynamicmetaobject.h>" << endl; |
548 */ | 552 */ |
549 if (java_class->isQObject()) | |
550 s << "#include <QObjectEntity.h>" << endl; | |
551 | |
552 s << "#include <iostream>" << endl; | 553 s << "#include <iostream>" << endl; |
553 | |
554 | |
555 | 554 |
556 Include inc = java_class->typeEntry()->include(); | 555 Include inc = java_class->typeEntry()->include(); |
557 if (!inc.name.isEmpty()) { | 556 if (!inc.name.isEmpty()) { |
558 s << "#include "; | 557 s << "#include "; |
559 if (inc.type == Include::IncludePath) | 558 if (inc.type == Include::IncludePath) |
587 writeShellSignatures(s, java_class); | 586 writeShellSignatures(s, java_class); |
588 | 587 |
589 writeDefaultConstructedValues(s, java_class); | 588 writeDefaultConstructedValues(s, java_class); |
590 | 589 |
591 if (hasCustomDestructor(java_class)) */ | 590 if (hasCustomDestructor(java_class)) */ |
592 if (!java_class->isQObject()) | 591 |
593 writeFinalDestructor(s, java_class); | 592 if (java_class->hasPublicDestructor() && (!java_class->baseClass() || !java_class->hasVirtualFunctions())) |
593 writeDestructor(s, java_class); | |
594 | 594 |
595 if (java_class->isQObject()) | 595 if (java_class->isQObject()) |
596 writeSignalsHandling(s, java_class); | 596 writeSignalsHandling(s, java_class); |
597 | 597 |
598 if (shellClass) { | 598 if (shellClass) { |
599 foreach (AbstractMetaFunction *function, java_class->functions()) { | 599 foreach (AbstractMetaFunction *function, java_class->functions()) { |
600 if (function->isConstructor() && !function->isPrivate()) | 600 if (function->isConstructor()) |
601 writeShellConstructor(s, function); | 601 writeShellConstructor(s, function); |
602 } | 602 } |
603 writeShellDestructor(s, java_class); | 603 |
604 | 604 if (java_class->typeEntry()->isObject()) |
605 if (!java_class->isQObject() && java_class->hasVirtualFunctions()) | 605 writeShellDestructor(s, java_class); |
606 writeQtdEntityFunction(s, java_class); | |
607 | 606 |
608 if (java_class->isQObject()) | 607 if (java_class->isQObject()) |
609 writeQObjectFunctions(s, java_class); | 608 writeQObjectFunctions(s, java_class); |
609 else if (java_class->typeEntry()->isObject()) | |
610 writeObjectFunctions(s, java_class); | |
611 | |
610 | 612 |
611 // Virtual overrides | 613 // Virtual overrides |
612 s << "// Virtual overrides" << endl; | 614 s << "// Virtual overrides" << endl; |
613 AbstractMetaFunctionList virtualFunctions = java_class->virtualFunctions(); | 615 AbstractMetaFunctionList virtualFunctions = java_class->virtualFunctions(); |
614 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { | 616 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { |
1384 s << arguments.at(i)->indexedName(); | 1386 s << arguments.at(i)->indexedName(); |
1385 if (i != arguments.size() - 1) | 1387 if (i != arguments.size() - 1) |
1386 s << ", "; | 1388 s << ", "; |
1387 } | 1389 } |
1388 s << ")"; | 1390 s << ")"; |
1391 | |
1389 if (cls->isQObject()) | 1392 if (cls->isQObject()) |
1390 s << "," << endl << " QtD_QObjectEntity(this, d_ptr)"; | 1393 s << "," << endl << " QtD_QObjectEntity(this, d_ptr)"; |
1391 else if (cls->hasVirtualFunctions()) | 1394 else if (cls->typeEntry()->isObject() && cls->hasVirtualFunctions()) |
1392 s << "," << endl << " QtD_Entity(d_ptr)"; | 1395 s << "," << endl << " QtD_Entity(d_ptr)"; |
1393 /* qtd s << " m_meta_object(0)," << endl; | 1396 /* qtd s << " m_meta_object(0)," << endl; |
1394 s << " m_vtable(0)," << endl | 1397 s << " m_vtable(0)," << endl |
1395 << " m_link(0)" << endl; | 1398 << " m_link(0)" << endl; |
1396 */ | 1399 */ |
1400 Indentation indent(INDENT); | 1403 Indentation indent(INDENT); |
1401 | 1404 |
1402 writeCodeInjections(s, java_function, cls, CodeSnip::Beginning, TypeSystem::ShellCode); | 1405 writeCodeInjections(s, java_function, cls, CodeSnip::Beginning, TypeSystem::ShellCode); |
1403 writeCodeInjections(s, java_function, cls, CodeSnip::End, TypeSystem::ShellCode); | 1406 writeCodeInjections(s, java_function, cls, CodeSnip::End, TypeSystem::ShellCode); |
1404 } | 1407 } |
1405 s << "}" << endl << endl; | 1408 s << "}" << endl << endl; |
1406 } | 1409 } |
1407 | 1410 |
1408 void CppImplGenerator::writeShellDestructor(QTextStream &s, const AbstractMetaClass *java_class) | 1411 void CppImplGenerator::writeShellDestructor(QTextStream &s, const AbstractMetaClass *java_class) |
1409 { | 1412 { |
1410 s << shellClassName(java_class) << "::~" | 1413 s << shellClassName(java_class) << "::~" |
1411 << shellClassName(java_class) << "()" << endl | 1414 << shellClassName(java_class) << "()" << endl |
1412 << "{" << endl; | 1415 << "{" << endl; |
1413 { | 1416 { |
1414 //s << " std::cout << \"In shell destructor of " << java_class->name() << ", nativeId: \" << this << std::endl;"; | 1417 s << " std::cout << \"In shell destructor of " << java_class->name() << ", nativeId: \" << this << std::endl;"; |
1415 if (java_class->isQObject()) | 1418 if (java_class->isQObject()) |
1416 s << " destroyEntity(this);"; | 1419 s << " destroyEntity(this);" << endl; |
1420 else | |
1421 s << " qtd_delete_d_object(dId);" << endl; | |
1417 } | 1422 } |
1418 s << "}" << endl << endl; | 1423 s << "}" << endl << endl; |
1419 } | 1424 } |
1420 | 1425 |
1421 void CppImplGenerator::writeCodeInjections(QTextStream &s, const AbstractMetaFunction *java_function, | 1426 void CppImplGenerator::writeCodeInjections(QTextStream &s, const AbstractMetaFunction *java_function, |
1727 Indentation indent(INDENT); | 1732 Indentation indent(INDENT); |
1728 writeBaseClassFunctionCall(s, java_function, implementor); | 1733 writeBaseClassFunctionCall(s, java_function, implementor); |
1729 s << "}" << endl << endl; | 1734 s << "}" << endl << endl; |
1730 } | 1735 } |
1731 | 1736 |
1732 void CppImplGenerator::writeQtdEntityFunction(QTextStream &s, const AbstractMetaClass *java_class) | 1737 void CppImplGenerator::writeObjectFunctions(QTextStream &s, const AbstractMetaClass *java_class) |
1733 { | 1738 { |
1734 s << "extern \"C\" DLL_PUBLIC void *__" << java_class->name() << "_entity(void *q_ptr)" << endl; | 1739 s << "extern \"C\" DLL_PUBLIC const void* qtd_" << java_class->name() << "_staticTypeId()" << endl; |
1735 s << "{" << endl; | 1740 s << "{" << endl; |
1736 { | 1741 { |
1737 Indentation indent(INDENT); | 1742 Indentation indent(INDENT); |
1738 s << INDENT << "QtD_Entity* a = dynamic_cast<QtD_Entity*>((" << java_class->qualifiedCppName() << "*)q_ptr);" << endl | 1743 s << INDENT << "return &typeid(" << java_class->qualifiedCppName() << ");" << endl; |
1739 << INDENT << "if (a != NULL)" << endl | |
1740 << INDENT << " return a->dId;" << endl | |
1741 << INDENT << "else" << endl | |
1742 << INDENT << " return NULL;" << endl; | |
1743 } | 1744 } |
1744 s << "}" << endl << endl; | 1745 s << "}" << endl << endl; |
1746 | |
1747 if (java_class->hasVirtualFunctions()) | |
1748 { | |
1749 if (!java_class->baseClass()) | |
1750 { | |
1751 s << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_dId(void *q_ptr)" << endl; | |
1752 s << "{" << endl; | |
1753 { | |
1754 Indentation indent(INDENT); | |
1755 s << INDENT << "QtD_Entity* a = dynamic_cast<QtD_Entity*>((" << java_class->qualifiedCppName() << "*)q_ptr);" << endl | |
1756 << INDENT << "if (a != NULL)" << endl | |
1757 << INDENT << " return a->dId;" << endl | |
1758 << INDENT << "else" << endl | |
1759 << INDENT << " return NULL;" << endl; | |
1760 } | |
1761 s << "}" << endl << endl; | |
1762 | |
1763 s << "extern \"C\" DLL_PUBLIC const void* qtd_" << java_class->name() << "_typeId(void *nativeId)" << endl; | |
1764 s << "{" << endl; | |
1765 { | |
1766 Indentation indent(INDENT); | |
1767 s << INDENT << "return &typeid((" << java_class->qualifiedCppName() << "*)nativeId);" << endl; | |
1768 } | |
1769 s << "}" << endl << endl; | |
1770 } | |
1771 else | |
1772 s << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->rootClass()->name() << "_dId(void *q_ptr);" << endl; | |
1773 } | |
1745 } | 1774 } |
1746 | 1775 |
1747 void CppImplGenerator::writeVirtualFunctionOverride(QTextStream &s, | 1776 void CppImplGenerator::writeVirtualFunctionOverride(QTextStream &s, |
1748 const AbstractMetaFunction *java_function, | 1777 const AbstractMetaFunction *java_function, |
1749 const AbstractMetaClass *implementor) | 1778 const AbstractMetaClass *implementor) |
1861 } else | 1890 } else |
1862 s << " jobject " << java_object_name; | 1891 s << " jobject " << java_object_name; |
1863 */ | 1892 */ |
1864 uint nativeArgCount = 0; | 1893 uint nativeArgCount = 0; |
1865 const AbstractMetaClass *cls = java_function->ownerClass(); | 1894 const AbstractMetaClass *cls = java_function->ownerClass(); |
1895 | |
1866 if (java_function->isConstructor() && | 1896 if (java_function->isConstructor() && |
1867 ( cls->hasVirtualFunctions() | 1897 cls->typeEntry()->isObject()) |
1868 || cls->typeEntry()->isObject() ) ) | |
1869 { | 1898 { |
1870 s << "void *d_ptr"; | 1899 s << "void *d_ptr"; |
1871 nativeArgCount++; | 1900 nativeArgCount++; |
1872 } | 1901 } |
1873 | 1902 |
2055 AbstractMetaArgumentList arguments = java_function->arguments(); | 2084 AbstractMetaArgumentList arguments = java_function->arguments(); |
2056 | 2085 |
2057 foreach (const AbstractMetaArgument *argument, arguments) { | 2086 foreach (const AbstractMetaArgument *argument, arguments) { |
2058 s << INDENT << "Q_UNUSED(" << argument->indexedName() << ")" << endl; | 2087 s << INDENT << "Q_UNUSED(" << argument->indexedName() << ")" << endl; |
2059 } | 2088 } |
2060 s << INDENT << default_return_statement_qt(java_function->type()) << ""; | 2089 s << INDENT << default_return_statement_qt(java_function->type()) << ""; |
2090 | |
2061 } else { | 2091 } else { |
2062 writeFinalFunctionSetup(s, java_function, qt_object_name, cls); | 2092 writeFinalFunctionSetup(s, java_function, qt_object_name, cls); |
2063 | 2093 |
2064 writeCodeInjections(s, java_function, java_function->implementingClass(), CodeSnip::Beginning, TypeSystem::NativeCode); | 2094 writeCodeInjections(s, java_function, java_function->implementingClass(), CodeSnip::Beginning, TypeSystem::NativeCode); |
2065 | 2095 |
2083 s << INDENT | 2113 s << INDENT |
2084 << "bool __do_static_call = __this_nativeId ? "; | 2114 << "bool __do_static_call = __this_nativeId ? "; |
2085 if (java_class->isQObject()) | 2115 if (java_class->isQObject()) |
2086 s << "QtD_QObjectEntity::getQObjectEntity((QObject*)__this_nativeId) : false;" << endl; | 2116 s << "QtD_QObjectEntity::getQObjectEntity((QObject*)__this_nativeId) : false;" << endl; |
2087 else | 2117 else |
2088 s << "__" << java_class->name() << "_entity(__this_nativeId) : false;" << endl; | 2118 s << "qtd_" << java_class->rootClass()->name() << "_dId(__this_nativeId) : false;" << endl; |
2089 } else { | 2119 } else { |
2090 option = OriginalName; | 2120 option = OriginalName; |
2091 } | 2121 } |
2092 | 2122 |
2093 // Call the Qt function on the java object | 2123 // Call the Qt function on the java object |
2286 } | 2316 } |
2287 s << "}" << endl << endl; | 2317 s << "}" << endl << endl; |
2288 } | 2318 } |
2289 } | 2319 } |
2290 | 2320 |
2291 void CppImplGenerator::writeFinalDestructor(QTextStream &s, const AbstractMetaClass *cls) | 2321 void CppImplGenerator::writeDestructor(QTextStream &s, const AbstractMetaClass *cls) |
2292 { | 2322 { |
2293 if (cls->hasConstructors()) { | 2323 if (!cls->hasConstructors()) |
2294 s << INDENT << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_destructor(void *ptr)" << endl | 2324 return; |
2295 << INDENT << "{" << endl; | 2325 |
2296 { | 2326 s << INDENT << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_destructor(void *ptr)" << endl |
2297 s << INDENT << "delete (" << shellClassName(cls) << " *)ptr;" << endl; | 2327 << INDENT << "{" << endl; |
2298 } | 2328 { |
2299 | 2329 QString className = cls->hasVirtualFunctions() ? cls->typeEntry()->name() : shellClassName(cls); |
2300 s << INDENT << "}" << endl << endl; | 2330 s << INDENT << "delete (" << className << " *)ptr;" << endl; |
2301 } | 2331 } |
2332 | |
2333 s << INDENT << "}" << endl << endl; | |
2302 } | 2334 } |
2303 | 2335 |
2304 void CppImplGenerator::writeFinalConstructor(QTextStream &s, | 2336 void CppImplGenerator::writeFinalConstructor(QTextStream &s, |
2305 const AbstractMetaFunction *java_function, | 2337 const AbstractMetaFunction *java_function, |
2306 const QString &qt_object_name, | 2338 const QString &qt_object_name, |
3049 return_type = jniReturnType(java_type); | 3081 return_type = jniReturnType(java_type); |
3050 return_type = fixCppTypeName(return_type); | 3082 return_type = fixCppTypeName(return_type); |
3051 // return_type = fixCppTypeName(java_type->typeEntry()->qualifiedCppName()); | 3083 // return_type = fixCppTypeName(java_type->typeEntry()->qualifiedCppName()); |
3052 } | 3084 } |
3053 /* if( (java_type->isValue() && !java_type->typeEntry()->isStructInD()) | 3085 /* if( (java_type->isValue() && !java_type->typeEntry()->isStructInD()) |
3054 || java_type->isObject() ) | 3086 // || java_type->isObject() ) |
3055 s << INDENT << return_type << " *" << java_name << " = (" << return_type << "*) "; | 3087 s << INDENT << return_type << " *" << java_name << " = (" << return_type << "*) "; |
3056 else*/ | 3088 else*/ |
3057 s << INDENT << return_type << " " << java_name << " = (" << return_type << ") "; | 3089 s << INDENT << return_type << " " << java_name << " = (" << return_type << ") "; |
3058 | 3090 |
3059 if (java_type->isQObject()) { | 3091 if (java_type->isQObject()) { |
3508 { | 3540 { |
3509 AbstractMetaArgumentList arguments = java_function->arguments(); | 3541 AbstractMetaArgumentList arguments = java_function->arguments(); |
3510 | 3542 |
3511 int written_arguments = 0; | 3543 int written_arguments = 0; |
3512 const AbstractMetaClass *cls = java_function->ownerClass(); | 3544 const AbstractMetaClass *cls = java_function->ownerClass(); |
3513 if (java_function->isConstructor() && cls->hasVirtualFunctions()) { | 3545 if (java_function->isConstructor() && cls->typeEntry()->isObject()) { |
3514 s << "d_ptr"; | 3546 s << "d_ptr"; |
3515 written_arguments++; | 3547 written_arguments++; |
3516 } | 3548 } |
3517 for (int i=0; i<arguments.size(); ++i) { | 3549 for (int i=0; i<arguments.size(); ++i) { |
3518 const AbstractMetaArgument *argument = arguments.at(i); | 3550 const AbstractMetaArgument *argument = arguments.at(i); |