Mercurial > projects > qtd
comparison generator/cppimplgenerator.cpp @ 310:5bcfe9e7db7f lifetime
Committing local changes
author | maxter <spambox@d-coding.com> |
---|---|
date | Wed, 23 Dec 2009 16:10:46 +0200 |
parents | 90131f64c9c9 |
children | 80b52f5e97b6 |
comparison
equal
deleted
inserted
replaced
263:a7b313b8b149 | 310:5bcfe9e7db7f |
---|---|
587 | 587 |
588 writeDefaultConstructedValues(s, java_class); | 588 writeDefaultConstructedValues(s, java_class); |
589 | 589 |
590 if (hasCustomDestructor(java_class)) */ | 590 if (hasCustomDestructor(java_class)) */ |
591 | 591 |
592 if (java_class->hasPublicDestructor() && (!java_class->baseClass() || !java_class->hasVirtualFunctions())) | 592 if (java_class->hasPublicDestructor() && !java_class->hasVirtualDestructor()) |
593 writeDestructor(s, java_class); | 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 |
599 foreach (AbstractMetaFunction *function, java_class->functions()) { | 599 foreach (AbstractMetaFunction *function, java_class->functions()) { |
600 if (function->isConstructor()) | 600 if (function->isConstructor()) |
601 writeShellConstructor(s, function); | 601 writeShellConstructor(s, function); |
602 } | 602 } |
603 | 603 |
604 if (java_class->hasVirtualFunctions()) | 604 if (java_class->isPolymorphic()) |
605 writeShellDestructor(s, java_class); | 605 writeShellDestructor(s, java_class); |
606 | 606 |
607 if (java_class->isQObject()) | 607 if (java_class->isQObject()) |
608 writeQObjectFunctions(s, java_class); | 608 writeQObjectFunctions(s, java_class); |
609 else if (java_class->typeEntry()->isObject()) | 609 else if (java_class->typeEntry()->isObject()) |
616 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { | 616 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { |
617 const AbstractMetaFunction *function = virtualFunctions.at(pos); | 617 const AbstractMetaFunction *function = virtualFunctions.at(pos); |
618 // qtd writeShellFunction(s, function, java_class, pos); | 618 // qtd writeShellFunction(s, function, java_class, pos); |
619 writeShellVirtualFunction(s, function, java_class, pos); | 619 writeShellVirtualFunction(s, function, java_class, pos); |
620 } | 620 } |
621 s << "// end ------------------------" << endl << endl; | |
621 | 622 |
622 if (cpp_shared) | 623 if (cpp_shared) |
623 writeInitCallbacks(s, java_class); | 624 writeInitCallbacks(s, java_class); |
624 | 625 |
625 // Functions in shell class | 626 // Functions in shell class |
627 AbstractMetaFunctionList shellFunctions = java_class->nonVirtualShellFunctions(); | 628 AbstractMetaFunctionList shellFunctions = java_class->nonVirtualShellFunctions(); |
628 for (int i=0; i<shellFunctions.size(); ++i) { | 629 for (int i=0; i<shellFunctions.size(); ++i) { |
629 const AbstractMetaFunction *function = shellFunctions.at(i); | 630 const AbstractMetaFunction *function = shellFunctions.at(i); |
630 writeShellFunction(s, function, java_class, -1); | 631 writeShellFunction(s, function, java_class, -1); |
631 } | 632 } |
633 s << "// end ------------------------" << endl << endl; | |
632 | 634 |
633 // Write public overrides for functions that are protected in the base class | 635 // Write public overrides for functions that are protected in the base class |
634 // so they can be accessed from the native callback | 636 // so they can be accessed from the native callback |
635 s << "// public overrides for functions that are protected in the base class" << endl; | 637 s << "// public overrides for functions that are protected in the base class" << endl; |
636 AbstractMetaFunctionList public_override_functions = java_class->publicOverrideFunctions(); | 638 AbstractMetaFunctionList public_override_functions = java_class->publicOverrideFunctions(); |
637 foreach (AbstractMetaFunction *function, public_override_functions) { | 639 foreach (AbstractMetaFunction *function, public_override_functions) { |
638 if(notWrappedYet(function)) | 640 if(notWrappedYet(function)) |
639 continue; | 641 continue; |
640 writePublicFunctionOverride(s, function, java_class); | 642 writePublicFunctionOverride(s, function, java_class); |
641 } | 643 } |
644 s << "// end ------------------------" << endl << endl; | |
642 | 645 |
643 // Write virtual function overries used to decide on static/virtual calls | 646 // Write virtual function overries used to decide on static/virtual calls |
644 s << "// Write virtual function overries used to decide on static/virtual calls" << endl; | 647 s << "// Write virtual function overries used to decide on static/virtual calls" << endl; |
645 AbstractMetaFunctionList virtual_functions = java_class->virtualOverrideFunctions(); | 648 AbstractMetaFunctionList virtual_functions = java_class->virtualOverrideFunctions(); |
646 foreach (const AbstractMetaFunction *function, virtual_functions) { | 649 foreach (const AbstractMetaFunction *function, virtual_functions) { |
647 if(notWrappedYet(function)) | 650 if(notWrappedYet(function)) |
648 continue; | 651 continue; |
649 writeVirtualFunctionOverride(s, function, java_class); | 652 writeVirtualFunctionOverride(s, function, java_class); |
650 } | 653 } |
654 s << "// end ------------------------" << endl << endl;; | |
651 } | 655 } |
652 | 656 |
653 writeExtraFunctions(s, java_class); | 657 writeExtraFunctions(s, java_class); |
654 /* qtd2 | 658 /* qtd2 |
655 writeToStringFunction(s, java_class); | 659 writeToStringFunction(s, java_class); |
661 // Signals | 665 // Signals |
662 AbstractMetaFunctionList signal_functions = signalFunctions(java_class); | 666 AbstractMetaFunctionList signal_functions = signalFunctions(java_class); |
663 for (int i=0; i<signal_functions.size(); ++i) | 667 for (int i=0; i<signal_functions.size(); ++i) |
664 writeSignalFunction(s, signal_functions.at(i), java_class, i); | 668 writeSignalFunction(s, signal_functions.at(i), java_class, i); |
665 */ | 669 */ |
666 s << "// ---externC---" << endl; | 670 s << "// extern C" << endl; |
667 | |
668 // Native callbacks (all java functions require native callbacks) | 671 // Native callbacks (all java functions require native callbacks) |
669 AbstractMetaFunctionList class_funcs = java_class->functionsInTargetLang(); | 672 AbstractMetaFunctionList class_funcs = java_class->functionsInTargetLang(); |
670 foreach (AbstractMetaFunction *function, class_funcs) { | 673 foreach (AbstractMetaFunction *function, class_funcs) { |
671 if (!function->isEmptyFunction()) | 674 if (!function->isEmptyFunction()) |
672 writeFinalFunction(s, function, java_class); | 675 writeFinalFunction(s, function, java_class); |
673 } | 676 } |
674 s << "// ---externC---end" << endl; | 677 s << "// end ------------------------" << endl << endl; |
675 | 678 |
676 | 679 |
677 class_funcs = java_class->queryFunctions(AbstractMetaClass::NormalFunctions | AbstractMetaClass::AbstractFunctions | AbstractMetaClass::NotRemovedFromTargetLang); | 680 class_funcs = java_class->queryFunctions(AbstractMetaClass::NormalFunctions | AbstractMetaClass::AbstractFunctions | AbstractMetaClass::NotRemovedFromTargetLang); |
678 foreach (AbstractMetaFunction *function, class_funcs) { | 681 foreach (AbstractMetaFunction *function, class_funcs) { |
679 if (function->implementingClass() != java_class) { | 682 if (function->implementingClass() != java_class) { |
685 s << "// Field accessors" << endl; | 688 s << "// Field accessors" << endl; |
686 foreach (AbstractMetaField *field, java_class->fields()) { | 689 foreach (AbstractMetaField *field, java_class->fields()) { |
687 if (field->wasPublic() || (field->wasProtected() && !java_class->isFinal())) | 690 if (field->wasPublic() || (field->wasProtected() && !java_class->isFinal())) |
688 writeFieldAccessors(s, field); | 691 writeFieldAccessors(s, field); |
689 } | 692 } |
693 s << "// end ------------------------" << endl << endl; | |
694 | |
690 /* | 695 /* |
691 s << "// writeFromNativeFunction" << endl; | 696 s << "// writeFromNativeFunction" << endl; |
692 writeFromNativeFunction(s, java_class); | 697 writeFromNativeFunction(s, java_class); |
693 | 698 |
694 if (java_class->isQObject()) | 699 if (java_class->isQObject()) |
709 // qtd writeJavaLangObjectOverrideFunctions(s, java_class); | 714 // qtd writeJavaLangObjectOverrideFunctions(s, java_class); |
710 | 715 |
711 if (java_class->isQObject()) | 716 if (java_class->isQObject()) |
712 { | 717 { |
713 s << endl << endl | 718 s << endl << endl |
714 << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_staticMetaObject() {" << endl | 719 << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_staticTypeId() {" << endl |
715 << " return (void*)&" << java_class->name() << "::staticMetaObject;" << endl | 720 << " return (void*)&" << java_class->name() << "::staticMetaObject;" << endl |
716 << "}" << endl; | 721 << "}" << endl; |
717 } | 722 } |
718 | 723 |
719 s << endl << endl; | 724 s << endl << endl; |
1389 } | 1394 } |
1390 s << ")"; | 1395 s << ")"; |
1391 | 1396 |
1392 if (cls->isQObject()) | 1397 if (cls->isQObject()) |
1393 s << "," << endl << " QtD_QObjectEntity(this, d_ptr)"; | 1398 s << "," << endl << " QtD_QObjectEntity(this, d_ptr)"; |
1394 else if (cls->hasVirtualFunctions()) | 1399 else if (cls->isPolymorphic()) |
1395 s << "," << endl << " QtD_Entity(d_ptr)"; | 1400 s << "," << endl << " QtD_Entity(d_ptr)"; |
1396 /* qtd s << " m_meta_object(0)," << endl; | 1401 /* qtd s << " m_meta_object(0)," << endl; |
1397 s << " m_vtable(0)," << endl | 1402 s << " m_vtable(0)," << endl |
1398 << " m_link(0)" << endl; | 1403 << " m_link(0)" << endl; |
1399 */ | 1404 */ |
1734 s << "}" << endl << endl; | 1739 s << "}" << endl << endl; |
1735 } | 1740 } |
1736 | 1741 |
1737 void CppImplGenerator::writeObjectFunctions(QTextStream &s, const AbstractMetaClass *java_class) | 1742 void CppImplGenerator::writeObjectFunctions(QTextStream &s, const AbstractMetaClass *java_class) |
1738 { | 1743 { |
1739 if (java_class->isPolymorphic()) | 1744 if (java_class == java_class->polymorphicBase()) |
1745 { | |
1746 if (java_class->isPolymorphic()) | |
1747 { | |
1748 s << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_dId(void *nativeId)" << endl | |
1749 << "{" << endl | |
1750 << " QtD_Entity *e = dynamic_cast<QtD_Entity*>((" << java_class->qualifiedCppName() << "*)nativeId);" << endl | |
1751 << " return e ? e->dId : NULL;" << endl | |
1752 << "}" << endl << endl; | |
1753 } | |
1754 | |
1755 if (!java_class->isQObject()) | |
1756 { | |
1757 s << "extern \"C\" DLL_PUBLIC const void* qtd_" << java_class->name() << "_typeId(void *nativeId)" << endl | |
1758 << "{" << endl | |
1759 << " return &typeid((" << java_class->qualifiedCppName() << "*)nativeId);" << endl | |
1760 << "}" << endl << endl; | |
1761 } | |
1762 } | |
1763 | |
1764 if (!java_class->isQObject()) | |
1740 { | 1765 { |
1741 s << "extern \"C\" DLL_PUBLIC const void* qtd_" << java_class->name() << "_staticTypeId()" << endl; | 1766 s << "extern \"C\" DLL_PUBLIC const void* qtd_" << java_class->name() << "_staticTypeId()" << endl; |
1742 s << "{" << endl; | 1767 s << "{" << endl; |
1743 { | 1768 { |
1744 Indentation indent(INDENT); | 1769 Indentation indent(INDENT); |
1745 s << INDENT << "return &typeid(" << java_class->qualifiedCppName() << ");" << endl; | 1770 s << INDENT << "return &typeid(" << java_class->qualifiedCppName() << ");" << endl; |
1746 } | 1771 } |
1747 s << "}" << endl << endl; | 1772 s << "}" << endl << endl; |
1748 | |
1749 if (!java_class->baseClass()) | |
1750 { | |
1751 s << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_dId(void *nativeId)" << endl | |
1752 << "{" << endl | |
1753 << " QtD_Entity *a = dynamic_cast<QtD_Entity*>((" << java_class->qualifiedCppName() << "*)nativeId);" << endl | |
1754 << " return a ? a->dId : NULL;" << endl | |
1755 << "}" << endl << endl | |
1756 | |
1757 << "extern \"C\" DLL_PUBLIC const void* qtd_" << java_class->name() << "_typeId(void *nativeId)" << endl | |
1758 << "{" << endl | |
1759 << " return &typeid((" << java_class->qualifiedCppName() << "*)nativeId);" << endl | |
1760 << "}" << endl << endl; | |
1761 } | |
1762 } | 1773 } |
1763 } | 1774 } |
1764 | 1775 |
1765 void CppImplGenerator::writeVirtualFunctionOverride(QTextStream &s, | 1776 void CppImplGenerator::writeVirtualFunctionOverride(QTextStream &s, |
1766 const AbstractMetaFunction *java_function, | 1777 const AbstractMetaFunction *java_function, |
1881 */ | 1892 */ |
1882 uint nativeArgCount = 0; | 1893 uint nativeArgCount = 0; |
1883 const AbstractMetaClass *cls = java_function->ownerClass(); | 1894 const AbstractMetaClass *cls = java_function->ownerClass(); |
1884 | 1895 |
1885 if (java_function->isConstructor() && | 1896 if (java_function->isConstructor() && |
1886 cls->hasVirtualFunctions()) | 1897 cls->isPolymorphic()) |
1887 { | 1898 { |
1888 s << "void *d_ptr"; | 1899 s << "void *d_ptr"; |
1889 nativeArgCount++; | 1900 nativeArgCount++; |
1890 } | 1901 } |
1891 | 1902 |
2102 s << INDENT | 2113 s << INDENT |
2103 << "bool __do_static_call = __this_nativeId ? "; | 2114 << "bool __do_static_call = __this_nativeId ? "; |
2104 if (java_class->isQObject()) | 2115 if (java_class->isQObject()) |
2105 s << "QtD_QObjectEntity::getQObjectEntity((QObject*)__this_nativeId) : false;" << endl; | 2116 s << "QtD_QObjectEntity::getQObjectEntity((QObject*)__this_nativeId) : false;" << endl; |
2106 else | 2117 else |
2107 s << "qtd_" << java_class->rootClass()->name() << "_dId(__this_nativeId) : false;" << endl; | 2118 s << "qtd_" << java_class->polymorphicBase()->name() << "_dId(__this_nativeId) : false;" << endl; |
2108 } else { | 2119 } else { |
2109 option = OriginalName; | 2120 option = OriginalName; |
2110 } | 2121 } |
2111 | 2122 |
2112 // Call the Qt function on the java object | 2123 // Call the Qt function on the java object |
2310 void CppImplGenerator::writeDestructor(QTextStream &s, const AbstractMetaClass *cls) | 2321 void CppImplGenerator::writeDestructor(QTextStream &s, const AbstractMetaClass *cls) |
2311 { | 2322 { |
2312 if (!cls->hasConstructors()) | 2323 if (!cls->hasConstructors()) |
2313 return; | 2324 return; |
2314 | 2325 |
2315 s << INDENT << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_destructor(void *ptr)" << endl | 2326 if (cls->polymorphicBase() == cls) |
2316 << INDENT << "{" << endl; | |
2317 { | 2327 { |
2318 QString className = cls->hasVirtualFunctions() ? cls->typeEntry()->name() : shellClassName(cls); | 2328 s << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_delete(void *ptr){" << endl; |
2319 s << INDENT << "delete (" << className << " *)ptr;" << endl; | 2329 QString className = cls->generateShellClass() ? shellClassName(cls) : cls->typeEntry()->name(); |
2320 } | 2330 s << " delete (" << className << " *)ptr;" << endl |
2321 | 2331 << "}" << endl << endl; |
2322 s << INDENT << "}" << endl << endl; | 2332 } |
2323 } | 2333 } |
2324 | 2334 |
2325 void CppImplGenerator::writeFinalConstructor(QTextStream &s, | 2335 void CppImplGenerator::writeFinalConstructor(QTextStream &s, |
2326 const AbstractMetaFunction *java_function, | 2336 const AbstractMetaFunction *java_function, |
2327 const QString &qt_object_name, | 2337 const QString &qt_object_name, |
2664 const QString &qt_name, | 2674 const QString &qt_name, |
2665 const QString &java_name, | 2675 const QString &java_name, |
2666 const AbstractMetaFunction *java_function, | 2676 const AbstractMetaFunction *java_function, |
2667 int argument_index) | 2677 int argument_index) |
2668 { | 2678 { |
2679 s << "//writeJavaToQt" << endl; // TMP | |
2680 | |
2669 // Conversion to C++: Shell code for return values, native code for arguments | 2681 // Conversion to C++: Shell code for return values, native code for arguments |
2670 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::ShellCode : TypeSystem::NativeCode; | 2682 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::ShellCode : TypeSystem::NativeCode; |
2671 if (writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) | 2683 if (writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) |
2672 return; | 2684 return; |
2673 | 2685 |
2692 const QString &java_name, | 2704 const QString &java_name, |
2693 const AbstractMetaFunction *java_function, | 2705 const AbstractMetaFunction *java_function, |
2694 int argument_index, | 2706 int argument_index, |
2695 Option options) | 2707 Option options) |
2696 { | 2708 { |
2709 s << "//writeJavaToQt 2" << endl; // TMP | |
2710 | |
2697 // Conversion to C++: Shell code for return values, native code for arguments | 2711 // Conversion to C++: Shell code for return values, native code for arguments |
2698 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::ShellCode : TypeSystem::NativeCode; | 2712 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::ShellCode : TypeSystem::NativeCode; |
2699 if (java_function && writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) | 2713 if (java_function && writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) |
2700 return; | 2714 return; |
2701 | 2715 |
2928 const QString &java_name, | 2942 const QString &java_name, |
2929 const AbstractMetaFunction *java_function, | 2943 const AbstractMetaFunction *java_function, |
2930 int argument_index, | 2944 int argument_index, |
2931 Option option) | 2945 Option option) |
2932 { | 2946 { |
2947 s << "writeQtToJava" << endl; | |
2933 | 2948 |
2934 // Conversion to Java: Native code for return values, shell code for arguments | 2949 // Conversion to Java: Native code for return values, shell code for arguments |
2935 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::NativeCode : TypeSystem::ShellCode; | 2950 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::NativeCode : TypeSystem::ShellCode; |
2936 /* qtd if (java_function && writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) | 2951 /* qtd if (java_function && writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) |
2937 return; | 2952 return; |
3529 { | 3544 { |
3530 AbstractMetaArgumentList arguments = java_function->arguments(); | 3545 AbstractMetaArgumentList arguments = java_function->arguments(); |
3531 | 3546 |
3532 int written_arguments = 0; | 3547 int written_arguments = 0; |
3533 const AbstractMetaClass *cls = java_function->ownerClass(); | 3548 const AbstractMetaClass *cls = java_function->ownerClass(); |
3534 if (java_function->isConstructor() && cls->hasVirtualFunctions()) { | 3549 if (java_function->isConstructor() && cls->isPolymorphic()) { |
3535 s << "d_ptr"; | 3550 s << "d_ptr"; |
3536 written_arguments++; | 3551 written_arguments++; |
3537 } | 3552 } |
3538 for (int i=0; i<arguments.size(); ++i) { | 3553 for (int i=0; i<arguments.size(); ++i) { |
3539 const AbstractMetaArgument *argument = arguments.at(i); | 3554 const AbstractMetaArgument *argument = arguments.at(i); |