Mercurial > projects > qtd
comparison generator/dgenerator.cpp @ 105:3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
author | eldar |
---|---|
date | Sun, 31 May 2009 01:38:39 +0000 |
parents | 64b874c86f9b |
children | 136c9ee83ee5 |
comparison
equal
deleted
inserted
replaced
104:64b874c86f9b | 105:3aa118a9ae71 |
---|---|
849 // return value marschalling | 849 // return value marschalling |
850 if(return_type) { | 850 if(return_type) { |
851 if ( ( has_return_type && d_function->argumentReplaced(0).isEmpty() )/* || d_function->isConstructor()*/) // qtd | 851 if ( ( has_return_type && d_function->argumentReplaced(0).isEmpty() )/* || d_function->isConstructor()*/) // qtd |
852 if(return_type->isQObject()) { | 852 if(return_type->isQObject()) { |
853 | 853 |
854 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(return_type->typeEntry()); | |
854 QString type_name = return_type->name(); | 855 QString type_name = return_type->name(); |
855 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry()); | 856 QString class_name = ctype->name(); |
856 if(ctype->isAbstract()) | 857 if(ctype->isAbstract()) |
857 type_name = type_name + "_ConcreteWrapper"; | 858 type_name = type_name + "_ConcreteWrapper"; |
858 | 859 /* |
859 s << INDENT << "if (__qt_return_value is null)" << endl | 860 s << INDENT << "if (__qt_return_value is null)" << endl |
860 << INDENT << " return null;" << endl | 861 << INDENT << " return null;" << endl |
861 << INDENT << "void* d_obj = __QObject_entity(__qt_return_value);" << endl | 862 << INDENT << "void* d_obj = __QObject_entity(__qt_return_value);" << endl |
862 << INDENT << "if (d_obj is null) {" << endl | 863 << INDENT << "if (d_obj is null) {" << endl |
863 << INDENT << " auto new_obj = new " << type_name << "(__qt_return_value, true);" << endl | 864 << INDENT << " auto new_obj = new " << type_name << "(__qt_return_value, true);" << endl |
864 << INDENT << " new_obj.__no_real_delete = true;" << endl | 865 << INDENT << " new_obj.__no_real_delete = true;" << endl |
865 << INDENT << " return new_obj;" << endl | 866 << INDENT << " return new_obj;" << endl |
866 << INDENT << "} else" << endl | 867 << INDENT << "} else" << endl |
867 << INDENT << " return cast(" << return_type->name() << ") d_obj;" << endl; | 868 << INDENT << " return cast(" << return_type->name() << ") d_obj;" << endl; |
869 */ | |
870 s << INDENT << "if (__qt_return_value is null)" << endl | |
871 << INDENT << " return null;" << endl | |
872 << INDENT << "void* d_obj = qtd_" << class_name << "_d_pointer(__qt_return_value);" << endl | |
873 << INDENT << "if (d_obj is null) {" << endl | |
874 << INDENT << " auto new_obj = new " << type_name << "(__qt_return_value, true);" << endl | |
875 << INDENT << " qtd_" << class_name << "_create_link(new_obj.nativeId, cast(void*) new_obj);" << endl | |
876 << INDENT << " new_obj.__no_real_delete = true;" << endl | |
877 << INDENT << " return new_obj;" << endl | |
878 << INDENT << "} else" << endl | |
879 << INDENT << " return cast(" << class_name << ") d_obj;" << endl; | |
880 | |
868 } | 881 } |
869 | 882 |
870 | 883 |
871 if (return_type->isValue() && !return_type->typeEntry()->isStructInD()) | 884 if (return_type->isValue() && !return_type->typeEntry()->isStructInD()) |
872 s << INDENT << "return new " << return_type->name() << "(__qt_return_value, false);" << endl; | 885 s << INDENT << "return new " << return_type->name() << "(__qt_return_value, false);" << endl; |
2397 if (!d_class->isInterface() && snip.language == TypeSystem::TargetLangFreeCode) { | 2410 if (!d_class->isInterface() && snip.language == TypeSystem::TargetLangFreeCode) { |
2398 s << endl; | 2411 s << endl; |
2399 snip.formattedCode(s, INDENT); | 2412 snip.formattedCode(s, INDENT); |
2400 } | 2413 } |
2401 } | 2414 } |
2402 /* --------------------------------------------------- */ | 2415 /* --------------------------------------------------- */ |
2403 | 2416 |
2404 interfaces = d_class->interfaces(); | 2417 interfaces = d_class->interfaces(); |
2405 if (!interfaces.isEmpty()) { | 2418 if (!interfaces.isEmpty()) { |
2406 for (int i=0; i<interfaces.size(); ++i) { | 2419 for (int i=0; i<interfaces.size(); ++i) { |
2407 AbstractMetaClass *iface = interfaces.at(i); | 2420 AbstractMetaClass *iface = interfaces.at(i); |
2411 } | 2424 } |
2412 } | 2425 } |
2413 | 2426 |
2414 if (!d_class->isInterface() && d_class->isAbstract()) { | 2427 if (!d_class->isInterface() && d_class->isAbstract()) { |
2415 s << endl; | 2428 s << endl; |
2416 /* qtd | 2429 |
2417 if (TypeDatabase::instance()->includeEclipseWarnings()) | |
2418 s << INDENT << "@SuppressWarnings(\"unused\")" << endl; | |
2419 */ | |
2420 s << INDENT << "public class " << d_class->name() << "_ConcreteWrapper : " << d_class->name() << " {" << endl; | 2430 s << INDENT << "public class " << d_class->name() << "_ConcreteWrapper : " << d_class->name() << " {" << endl; |
2421 | 2431 |
2422 { | 2432 { |
2423 Indentation indent(INDENT); | 2433 Indentation indent(INDENT); |
2424 s << INDENT << "public this(void* native_id, bool no_real_delete = true) {" << endl | 2434 s << INDENT << "public this(void* native_id, bool no_real_delete = true) {" << endl |
2503 if (d_class->generateShellClass()) { // qtd2 | 2513 if (d_class->generateShellClass()) { // qtd2 |
2504 if (d_class->hasVirtualFunctions() | 2514 if (d_class->hasVirtualFunctions() |
2505 && (d_class->typeEntry()->isObject() || d_class->typeEntry()->isQObject()) ) | 2515 && (d_class->typeEntry()->isObject() || d_class->typeEntry()->isQObject()) ) |
2506 s << endl << "extern (C) void *__" << d_class->name() << "_entity(void *q_ptr);" << endl << endl; | 2516 s << endl << "extern (C) void *__" << d_class->name() << "_entity(void *q_ptr);" << endl << endl; |
2507 } | 2517 } |
2518 | |
2508 if (d_class->isQObject()) { | 2519 if (d_class->isQObject()) { |
2509 s<< "private extern (C) void qtd_D_" << d_class->name() << "_delete(void *d_ptr) {" << endl | 2520 writeQObjectFunctions(s, d_class); |
2521 | |
2522 s << "private extern (C) void qtd_D_" << d_class->name() << "_delete(void *d_ptr) {" << endl | |
2510 << " auto d_ref = cast(QObject) d_ptr;" << endl | 2523 << " auto d_ref = cast(QObject) d_ptr;" << endl |
2511 << " d_ref.__no_real_delete = true;" << endl | 2524 << " d_ref.__no_real_delete = true;" << endl |
2512 << " delete d_ref;" << endl | 2525 << " delete d_ref;" << endl |
2513 << "}" << endl; | 2526 << "}" << endl; |
2514 } | 2527 } |
2619 foreach (AbstractMetaClass *cls, includedClassesList) { | 2632 foreach (AbstractMetaClass *cls, includedClassesList) { |
2620 m_isRecursive = true; | 2633 m_isRecursive = true; |
2621 write(s, cls); | 2634 write(s, cls); |
2622 m_isRecursive = false; | 2635 m_isRecursive = false; |
2623 } | 2636 } |
2637 } | |
2638 | |
2639 void DGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class) | |
2640 { | |
2641 s << "extern(C) void* qtd_" << d_class->name() << "_d_pointer(void *obj);" << endl | |
2642 << "extern(C) void qtd_" << d_class->name() << "_create_link(void *obj, void* d_obj);" << endl << endl; | |
2624 } | 2643 } |
2625 | 2644 |
2626 /* | 2645 /* |
2627 void DGenerator::writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class) | 2646 void DGenerator::writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class) |
2628 { | 2647 { |
3231 s << INDENT << "bool gc_managed = " << arg->argumentName() << " is null ? true : false;" << endl | 3250 s << INDENT << "bool gc_managed = " << arg->argumentName() << " is null ? true : false;" << endl |
3232 << INDENT << ctor_call << "(__qt_return_value, gc_managed);" << endl; | 3251 << INDENT << ctor_call << "(__qt_return_value, gc_managed);" << endl; |
3233 } else { | 3252 } else { |
3234 s << INDENT << ctor_call << "(__qt_return_value, true);" << endl; | 3253 s << INDENT << ctor_call << "(__qt_return_value, true);" << endl; |
3235 } | 3254 } |
3255 | |
3256 // creating a link object associated with the current QObject for signal handling and metadata | |
3257 s << INDENT << "qtd_" << d_function->ownerClass()->name() << "_create_link(this.nativeId, cast(void*) this);" << endl; | |
3236 } | 3258 } |
3237 else | 3259 else |
3238 s << INDENT << "this(__qt_return_value);" << endl; | 3260 s << INDENT << "this(__qt_return_value);" << endl; |
3239 } | 3261 } |
3240 s << INDENT << "}" << endl << endl; | 3262 s << INDENT << "}" << endl << endl; |