comparison generator/cppimplgenerator.cpp @ 270:49bfc86ff583

true emit of Qt signals.
author eldar
date Thu, 24 Sep 2009 12:59:48 +0000
parents 073b9153ed8a
children 7243f9ed2307
comparison
equal deleted inserted replaced
269:cc9080066035 270:49bfc86ff583
385 s += "extern \"C\" DLL_PUBLIC "; 385 s += "extern \"C\" DLL_PUBLIC ";
386 /* qtd 386 /* qtd
387 if (options & CppImplGenerator::JNIExport) 387 if (options & CppImplGenerator::JNIExport)
388 s += "Q_DECL_EXPORT "; 388 s += "Q_DECL_EXPORT ";
389 */ 389 */
390 if (options & CppImplGenerator::ReturnType) { 390 if (options & CppImplGenerator::ReturnType)
391 s += return_type; 391 s += return_type + " ";
392 s += " "; 392 else
393 } 393 s += "void ";
394 /* qtd 394 /* qtd
395 if (options & CppImplGenerator::JNIExport) 395 if (options & CppImplGenerator::JNIExport)
396 s += "JNICALL QTJAMBI_FUNCTION_PREFIX("; 396 s += "JNICALL QTJAMBI_FUNCTION_PREFIX(";
397 397
398 s += "Java_"; 398 s += "Java_";
653 writeToStringFunction(s, java_class); 653 writeToStringFunction(s, java_class);
654 654
655 if (java_class->hasCloneOperator()) { 655 if (java_class->hasCloneOperator()) {
656 writeCloneFunction(s, java_class); 656 writeCloneFunction(s, java_class);
657 } 657 }
658 658 */
659 // Signals 659 // Signals emitters
660 AbstractMetaFunctionList signal_functions = signalFunctions(java_class); 660 AbstractMetaFunctionList signal_functions = signalFunctions(java_class);
661 for (int i=0; i<signal_functions.size(); ++i) 661 for (int i=0; i<signal_functions.size(); ++i)
662 writeSignalFunction(s, signal_functions.at(i), java_class, i); 662 {
663 */ 663 const AbstractMetaFunction *function = signal_functions.at(i);
664 if(!function->isPrivate())
665 writeFinalFunction(s, signal_functions.at(i), java_class);
666 }
664 s << "// ---externC---" << endl; 667 s << "// ---externC---" << endl;
665 668
666 // Native callbacks (all java functions require native callbacks) 669 // Native callbacks (all java functions require native callbacks)
667 AbstractMetaFunctionList class_funcs = java_class->functionsInTargetLang(); 670 AbstractMetaFunctionList class_funcs = java_class->functionsInTargetLang();
668 foreach (AbstractMetaFunction *function, class_funcs) { 671 foreach (AbstractMetaFunction *function, class_funcs) {
1289 << " emit_callbacks_" << java_class->name() << "[_id](this->dId, _a);" << endl 1292 << " emit_callbacks_" << java_class->name() << "[_id](this->dId, _a);" << endl
1290 << " return -1;" << endl 1293 << " return -1;" << endl
1291 << "}" << endl << endl; 1294 << "}" << endl << endl;
1292 } 1295 }
1293 1296
1294 void CppImplGenerator::writeSignalHandler(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunction *function) 1297 void CppImplGenerator::writeSignalEmitter(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunction *function)
1295 { 1298 {
1296 QString extra_args, extra_call_args, conversion_code; 1299 Q_ASSERT(d_class);
1297 QTextStream s2(&conversion_code); 1300
1298 1301 if (function->isModifiedRemoved(TypeSystem::NativeCode))
1302 return;
1303
1304 const AbstractMetaClass *cls = d_class ? d_class : function->ownerClass();
1305
1306 QString function_signature = cls->name() + "::" + function->signature();
1307
1308 s << "// " << function_signature << endl;
1309
1310 const QString qt_object_name = function->isStatic() ? shellClassName(cls) : "__qt_this";
1311
1312 // we are not wrapping some functions depending on arguments because API is not yet full
1313 if (notWrappedYet(function))
1314 return;
1315
1316 // function signature...
1317 bool callThrough = function->needsCallThrough();
1318 // uint options = m_native_jump_table ? ReturnType | ExternC : StandardJNISignature;
1319 writeFunctionName(s, function, cls, ExternC);
1320 s << endl;
1321 writeFinalFunctionArguments(s, function);
1322 s << endl << "{" << endl;
1299 Indentation indent(INDENT); 1323 Indentation indent(INDENT);
1300 1324
1301 AbstractMetaArgumentList arguments = function->arguments(); 1325 writeFinalFunctionSetup(s, function, qt_object_name, cls);
1302 foreach (AbstractMetaArgument *argument, arguments) { 1326
1303 if(argument->type()->isContainer()) { 1327 s << "void *args[] = {NULL";
1304 QString arg_name = argument->indexedName(); 1328 // create an array of pointers to args
1305 const AbstractMetaType *arg_type = argument->type(); 1329 /* AbstractMetaArgumentList arguments = java_function->arguments();
1306 extra_args += ", DArray " + arg_name; 1330 foreach (const AbstractMetaArgument *argument, arguments) {
1307 extra_call_args += ", " + arg_name + "_arr"; 1331 s << ", ";
1308 1332 if (!argument->type()->isPrimitive()
1309 s2 << INDENT; 1333 || !java_function->conversionRule(TypeSystem::NativeCode, argument->argumentIndex() + 1).isEmpty()) {
1310 writeTypeInfo(s2, arg_type, NoOption); 1334 // s << &qt_arg + n
1311 s2 << arg_name << " = (*reinterpret_cast< "; 1335 }
1312 writeTypeInfo(s2, arg_type, ExcludeReference); 1336 }
1313 s2 << "(*)>(args[" << argument->argumentIndex() + 1 << "]));" << endl 1337 */
1314 << INDENT << QString("DArray %1_arr;").arg(arg_name) << endl 1338 s << endl << "}";
1315 << INDENT << QString("DArray *__d_%1 = &%1_arr;").arg(arg_name); 1339 s << endl << endl;
1316
1317 writeQtToJava(s2,
1318 arg_type,
1319 arg_name,
1320 "__d_" + arg_name,
1321 function,
1322 argument->argumentIndex() + 1,
1323 Option(VirtualDispatch));
1324 }
1325 }
1326 QString sig_name = signalExternName(d_class, function);
1327 s << "extern \"C\" DLL_PUBLIC void " << sig_name << "_handle_in_d(void* d_entity, void** args" << extra_args <<");" << endl
1328 << "extern \"C\" DLL_PUBLIC void " << sig_name << "_handle(void* d_entity, void** args)" << endl
1329 << "{" << endl
1330 << conversion_code << endl
1331 << INDENT << sig_name << "_handle_in_d(d_entity, args" << extra_call_args << ");" << endl
1332 << "}" << endl;
1333
1334 } 1340 }
1335 1341
1336 void CppImplGenerator::writeSignalsHandling(QTextStream &s, const AbstractMetaClass *java_class) 1342 void CppImplGenerator::writeSignalsHandling(QTextStream &s, const AbstractMetaClass *java_class)
1337 { 1343 {
1338 s << "extern \"C\" typedef void (*EmitCallback)(void*, void**);" << endl; 1344 s << "extern \"C\" typedef void (*EmitCallback)(void*, void**);" << endl;