Mercurial > projects > qtd
annotate generator/cppimplgenerator.cpp @ 303:98b211f3ee34 signals
fix for #19
author | eldar_ins@eldar-laptop |
---|---|
date | Sat, 12 Dec 2009 16:01:55 +0500 |
parents | 4d8481385c71 |
children | 04b52676b45f |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** | |
5 ** This file is part of Qt Jambi. | |
6 ** | |
7 ** * Commercial Usage | |
8 * Licensees holding valid Qt Commercial licenses may use this file in | |
9 * accordance with the Qt Commercial License Agreement provided with the | |
10 * Software or, alternatively, in accordance with the terms contained in | |
11 * a written agreement between you and Nokia. | |
12 * | |
13 * | |
14 * GNU General Public License Usage | |
15 * Alternatively, this file may be used under the terms of the GNU | |
16 * General Public License versions 2.0 or 3.0 as published by the Free | |
17 * Software Foundation and appearing in the file LICENSE.GPL included in | |
18 * the packaging of this file. Please review the following information | |
19 * to ensure GNU General Public Licensing requirements will be met: | |
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
22 * exception, Nokia gives you certain additional rights. These rights | |
23 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
24 * the file GPL_EXCEPTION.txt in this package. | |
25 * | |
26 * Qt for Windows(R) Licensees | |
27 * As a special exception, Nokia, as the sole copyright holder for Qt | |
28 * Designer, grants users of the Qt/Eclipse Integration plug-in the | |
29 * right for the Qt/Eclipse Integration to link to functionality | |
30 * provided by Qt Designer and its related libraries. | |
31 * | |
32 * | |
33 * If you are unsure which license is appropriate for your use, please | |
34 * contact the sales department at qt-sales@nokia.com. | |
35 | |
36 ** | |
37 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
38 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 #include "cppimplgenerator.h" | |
43 #include "dgenerator.h" | |
44 #include "reporthandler.h" | |
45 | |
46 #include <QDir> | |
47 #include <QtDebug> | |
48 #include <QVariant> | |
49 #include <iostream> | |
50 #define VOID_POINTER_ORDINAL 8 | |
51 | |
52 static Indentor INDENT; | |
53 | |
54 QString jni_signature(const AbstractMetaFunction *function, JNISignatureFormat format) | |
55 { | |
56 QString returned = "("; | |
57 AbstractMetaArgumentList arguments = function->arguments(); | |
58 foreach (const AbstractMetaArgument *argument, arguments) { | |
59 if (!function->argumentRemoved(argument->argumentIndex() + 1)) { | |
60 QString modified_type = function->typeReplaced(argument->argumentIndex()+1); | |
61 | |
62 if (modified_type.isEmpty()) | |
63 returned += jni_signature(argument->type(), format); | |
64 else | |
65 returned += jni_signature(modified_type, format); | |
66 } | |
67 } | |
68 | |
69 returned += ")"; | |
70 | |
71 QString modified_type = function->typeReplaced(0); | |
72 if (modified_type.isEmpty()) | |
73 returned += jni_signature(function->type(), format); | |
74 else | |
75 returned += jni_signature(modified_type, format); | |
76 | |
77 return returned; | |
78 } | |
79 | |
80 QString jni_signature(const QString &_full_name, JNISignatureFormat format) | |
81 { | |
82 QString signature; | |
83 QString full_name = _full_name; | |
84 | |
85 if (full_name.endsWith("[]")) { | |
86 full_name.chop(2); | |
87 signature = "["; | |
88 } | |
89 | |
90 int start = 0, end = -1; | |
91 while ( (start = full_name.indexOf("<")) >= 0 && (end = full_name.indexOf(">")) >= 0 ) { | |
92 full_name.remove(start, end - start + 1); | |
93 } | |
94 | |
95 static QHash<QString, QString> table; | |
96 if (table.isEmpty()) { | |
97 table["boolean"] = "Z"; | |
98 table["byte"] = "B"; | |
99 table["char"] = "C"; | |
100 table["short"] = "S"; | |
101 table["int"] = "I"; | |
102 table["long"] = "J"; | |
103 table["float"] = "F"; | |
104 table["double"] = "D"; | |
105 } | |
106 | |
107 if (format == Underscores) | |
108 signature.replace("[", "_3"); | |
109 | |
110 if (table.contains(full_name)) { | |
111 signature += table[full_name]; | |
112 } else if (format == Underscores) { | |
113 signature.replace("[", "_3"); | |
114 signature += "L"; | |
115 signature += QString(full_name).replace("_", "_1").replace('.', '_').replace("$", "_00024"); | |
116 signature += "_2"; | |
117 } else { | |
118 signature += "L"; | |
119 signature += QString(full_name).replace('.', '/'); | |
120 signature += ";"; | |
121 } | |
122 | |
123 return signature; | |
124 } | |
125 | |
126 QString jni_signature(const AbstractMetaType *java_type, JNISignatureFormat format) | |
127 { | |
128 if (!java_type) | |
129 return "V"; | |
130 | |
131 if (java_type->isArray()) { | |
132 return "_3" + jni_signature(java_type->arrayElementType(), format); | |
133 } else if (java_type->isNativePointer()) { | |
134 if (format == Underscores) | |
135 return "Lcom_trolltech_qt_QNativePointer_2"; | |
136 else | |
137 return "Lcom/trolltech/qt/QNativePointer;"; | |
138 } else if (java_type->isIntegerEnum() || java_type->isIntegerFlags() | |
139 || (format == Underscores && (java_type->isEnum() || java_type->isFlags()))) { | |
140 return "I"; | |
141 } else if (java_type->isThread()) { | |
142 if (format == Underscores) | |
143 return "Ljava_lang_Thread_2"; | |
144 else | |
145 return "Ljava/lang/Thread;"; | |
146 } | |
147 | |
148 | |
149 | |
150 QString name = java_type->name(); | |
151 if (java_type->isObject()) { | |
152 if (const InterfaceTypeEntry *ie | |
153 = static_cast<const ObjectTypeEntry *>(java_type->typeEntry())->designatedInterface()) | |
154 name = ie->targetLangName(); | |
155 } else if (java_type->isTargetLangEnum()) { | |
156 const EnumTypeEntry *et = static_cast<const EnumTypeEntry *>(java_type->typeEntry()); | |
157 name = et->javaQualifier() + "$" + et->targetLangName(); | |
158 | |
159 } else if (java_type->isTargetLangFlags()) { | |
160 const FlagsTypeEntry *ft = static_cast<const FlagsTypeEntry *>(java_type->typeEntry()); | |
161 name = ft->originator()->javaQualifier() + "$" + ft->targetLangName(); | |
162 } | |
163 | |
164 return jni_signature( (java_type->package().isEmpty() ? QString() : java_type->package() + ".") + name, format); | |
165 } | |
166 | |
167 static QHash<QString, QString> table; | |
168 QString default_return_statement_qt(const AbstractMetaType *java_type, Generator::Option options = Generator::NoOption) | |
169 { | |
170 QString returnStr = ((options & Generator::NoReturnStatement) == 0 ? "return" : ""); | |
171 if (!java_type) | |
172 return returnStr; | |
173 | |
174 if (table.isEmpty()) { | |
175 table["bool"] = "false"; | |
176 table["byte"] = "0"; | |
177 table["char"] = "0"; | |
178 table["short"] = "0"; | |
179 table["int"] = "0"; | |
180 table["long"] = "0"; | |
181 table["float"] = "0f"; | |
182 table["double"] = "0.0"; | |
183 table["java.lang.Object"] = "0"; | |
184 } | |
185 | |
186 QString signature = table.value(java_type->typeEntry()->targetLangName()); | |
187 | |
188 if (!signature.isEmpty()) | |
189 return returnStr + " " + signature; | |
190 | |
191 Q_ASSERT(!java_type->isPrimitive()); | |
192 if (java_type->isJObjectWrapper()) | |
193 return returnStr + " JObjectWrapper()"; | |
194 if (java_type->isVariant()) | |
195 return returnStr + " QVariant()"; | |
196 if (java_type->isTargetLangString()) | |
197 return returnStr + " QString()"; | |
198 if (java_type->isTargetLangChar()) | |
199 return returnStr + " QChar()"; | |
200 else if (java_type->isEnum()) | |
201 return returnStr + " " + java_type->typeEntry()->name() + "(0)"; | |
202 else if (java_type->isContainer() && ((ContainerTypeEntry *)java_type->typeEntry())->type() == ContainerTypeEntry::StringListContainer) | |
203 return returnStr + " " + java_type->typeEntry()->name() + "()"; | |
204 else if (java_type->isValue() || java_type->isContainer()) | |
205 return returnStr + " " + java_type->cppSignature() + "()"; | |
206 else | |
207 return returnStr + " 0"; | |
208 } | |
209 | |
210 QString default_return_statement_java(const AbstractMetaType *java_type) | |
211 { | |
212 if (!java_type) | |
213 return "return"; | |
214 if (java_type->isArray()) | |
215 return "return null"; | |
216 | |
217 if (table.isEmpty()) { | |
218 table["boolean"] = "false"; | |
219 table["byte"] = "0"; | |
220 table["char"] = "0"; | |
221 table["short"] = "0"; | |
222 table["int"] = "0"; | |
223 table["long"] = "0"; | |
224 table["float"] = "0f"; | |
225 table["double"] = "0.0"; | |
226 table["java.lang.Object"] = "0"; | |
227 } | |
228 | |
229 QString signature = table.value(java_type->typeEntry()->targetLangName()); | |
230 if (!signature.isEmpty()) | |
231 return "return " + signature; | |
232 | |
233 Q_ASSERT(!java_type->isPrimitive()); | |
234 return "return 0"; | |
235 } | |
236 | |
237 /* Used to decide how which of the Call[Xxx]Method functions to call | |
238 */ | |
239 QByteArray jniTypeName(const QString &name) { | |
240 static QHash<QString, const char *> table; | |
241 if (table.isEmpty()) { | |
242 table["jboolean"] = "Boolean"; | |
243 table["jbyte"] = "Byte"; | |
244 table["jchar"] = "Char"; | |
245 table["jshort"] = "Short"; | |
246 table["jint"] = "Int"; | |
247 table["jlong"] = "Long"; | |
248 table["jfloat"] = "Float"; | |
249 table["jdouble"] = "Double"; | |
250 table["jobject"] = "Object"; | |
251 } | |
252 | |
253 return table[name]; | |
254 } | |
255 | |
256 QByteArray jniName(const QString &name) { | |
257 TypeEntry *entry = TypeDatabase::instance()->findType(name); | |
258 if (entry) | |
259 return entry->name().toLatin1(); | |
260 else | |
261 return "void *"; | |
262 } | |
263 | |
264 QString CppImplGenerator::jniReturnName(const AbstractMetaFunction *java_function, uint options, bool d_export) | |
265 { | |
20 | 266 AbstractMetaType *f_type = java_function->type(); |
267 | |
268 QString return_type = translateType(f_type, EnumAsInts, d_export); | |
1 | 269 QString new_return_type = java_function->typeReplaced(0); |
270 if (!new_return_type.isEmpty()) { | |
20 | 271 if(f_type && f_type->isPrimitive()) { |
272 if (d_export) | |
273 return_type = new_return_type; | |
274 } else | |
275 return_type = jniName(new_return_type); | |
1 | 276 } |
277 | |
278 // qtd | |
279 if (f_type) { | |
81 | 280 if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) |
1 | 281 return_type = "void"; |
282 else if (f_type->isObject() || f_type->isReference() || f_type->isValue() || f_type->isQObject()) | |
283 return_type = "void*"; | |
284 if (f_type->isVariant()) | |
285 return_type = "void*"; | |
286 } | |
287 | |
288 if (options & CppImplGenerator::ExternC && java_function->isConstructor()) | |
289 return_type = "void*"; | |
290 if (options & CppImplGenerator::ExternC && f_type) | |
291 if (f_type->isTargetLangString() || f_type->typeEntry()->isContainer()) | |
292 return_type = "void"; | |
293 // qtd end | |
294 | |
295 return return_type; | |
296 } | |
297 | |
298 QString CppImplGenerator::jniReturnType(const AbstractMetaType *f_type, uint options) | |
299 { | |
300 QString return_type = translateType(f_type, EnumAsInts); | |
301 | |
302 // qtd | |
303 if (f_type) { | |
304 if (f_type->typeEntry()->isStructInD()) | |
305 return_type = f_type->typeEntry()->qualifiedCppName(); | |
306 else if (f_type->isObject() || f_type->isReference() || f_type->isValue() || f_type->isQObject()) | |
307 return_type = "void*"; | |
308 if (f_type->isVariant()) | |
309 return_type = "void*"; | |
310 } | |
311 | |
312 if (options & CppImplGenerator::ExternC && f_type) | |
313 if (f_type->isTargetLangString()) | |
314 return_type = "void"; | |
315 // qtd end | |
316 return return_type; | |
317 } | |
318 | |
319 QByteArray jniTypeName(const AbstractMetaType *java_type) | |
320 { | |
321 if (!java_type) { | |
322 return "Void"; | |
323 } else if (java_type->isTargetLangChar()) { | |
324 return "Char"; | |
325 } else if (java_type->isPrimitive()) { | |
326 return jniTypeName(java_type->typeEntry()->jniName()); | |
327 } else if (java_type->isIntegerEnum() || java_type->isIntegerFlags()) { | |
328 return "Int"; | |
329 } else { | |
330 return "Object"; | |
331 } | |
332 } | |
333 | |
334 QByteArray newXxxArray(const AbstractMetaType *java_type) | |
335 { | |
336 return "New" + jniTypeName(java_type) + "Array"; | |
337 } | |
338 | |
339 QByteArray setXxxArrayElement(const AbstractMetaType *java_type) | |
340 { | |
341 Q_ASSERT(java_type); | |
342 return "Set" + jniTypeName(java_type) + "ArrayElement"; | |
343 } | |
344 | |
345 QByteArray getXxxArrayElement(const AbstractMetaType *java_type) | |
346 { | |
347 Q_ASSERT(java_type); | |
348 return "Get" + jniTypeName(java_type) + "ArrayElement"; | |
349 } | |
350 | |
351 QByteArray getXxxArrayRegion(const AbstractMetaType *java_type) | |
352 { | |
353 Q_ASSERT(java_type); | |
354 return "Get" + jniTypeName(java_type) + "ArrayRegion"; | |
355 } | |
356 | |
357 QByteArray setXxxArrayRegion(const AbstractMetaType *java_type) | |
358 { | |
359 Q_ASSERT(java_type); | |
360 return "Set" + jniTypeName(java_type) + "ArrayRegion"; | |
361 } | |
362 | |
363 QByteArray callXxxMethod(const AbstractMetaType *java_type) | |
364 { | |
365 return "Call" + jniTypeName(java_type) + "Method"; | |
366 } | |
367 | |
368 QByteArray callXxxMethod(const QString &name) { | |
369 TypeEntry *entry = TypeDatabase::instance()->findType(name); | |
370 if (entry && entry->isPrimitive()) | |
371 return "Call" + jniTypeName(entry->jniName()) + "Method"; | |
372 else | |
373 return "CallObjectMethod"; | |
374 } | |
375 | |
376 QString jni_function_signature(QString package, QString class_name, | |
377 const QString &function_name, | |
378 const QString &return_type, | |
379 const QString &mangled_arguments = QString(), | |
380 uint options = CppImplGenerator::StandardJNISignature) | |
381 { | |
382 QString s; | |
383 | |
384 if (options & CppImplGenerator::ExternC) | |
385 s += "extern \"C\" DLL_PUBLIC "; | |
386 /* qtd | |
387 if (options & CppImplGenerator::JNIExport) | |
388 s += "Q_DECL_EXPORT "; | |
389 */ | |
270 | 390 if (options & CppImplGenerator::ReturnType) |
391 s += return_type + " "; | |
392 else | |
393 s += "void "; | |
1 | 394 /* qtd |
395 if (options & CppImplGenerator::JNIExport) | |
396 s += "JNICALL QTJAMBI_FUNCTION_PREFIX("; | |
397 | |
398 s += "Java_"; | |
399 | |
400 s += package.replace(".", "_"); // qtd .replace("_", "_1") | |
401 s += '_'; | |
402 s += class_name; // qtd .replace("_", "_1"); | |
403 s += '_'; | |
404 */ | |
405 s += QString(function_name); //.replace("_", "_1"); | |
406 // s += mangled_arguments; | |
407 | |
408 /* qtd | |
409 if (options & CppImplGenerator::JNIExport) | |
410 s += ")"; | |
411 */ | |
412 return s; | |
413 } | |
414 | |
415 QString CppImplGenerator::fileNameForClass(const AbstractMetaClass *java_class) const | |
416 { | |
417 return QString("%1_shell.cpp").arg(java_class->name()); | |
418 } | |
419 | |
420 void CppImplGenerator::writeSignalFunction(QTextStream &s, const AbstractMetaFunction *signal, const AbstractMetaClass *cls, | |
421 int pos) | |
422 { | |
423 writeFunctionSignature(s, signal, cls, signalWrapperPrefix(), | |
424 Option(OriginalName | OriginalTypeDescription), | |
425 "QtJambi_SignalWrapper_"); | |
426 s << endl << "{" << endl; | |
427 { | |
428 AbstractMetaArgumentList arguments = signal->arguments(); | |
429 Indentation indent(INDENT); | |
430 | |
431 if (arguments.size() > 0) | |
432 s << INDENT << "jvalue arguments[" << arguments.size() << "];" << endl; | |
433 else | |
434 s << INDENT << "jvalue *arguments = 0;" << endl; | |
435 s << INDENT << "JNIEnv *__jni_env = qtjambi_current_environment();" << endl | |
436 << INDENT << "__jni_env->PushLocalFrame(100);" << endl; | |
437 | |
438 for (int i=0; i<arguments.size(); ++i) { | |
439 const AbstractMetaArgument *argument = arguments.at(i); | |
440 writeQtToJava(s, | |
441 argument->type(), | |
442 argument->indexedName(), | |
443 "__java_" + argument->indexedName(), | |
444 signal, | |
445 argument->argumentIndex() + 1, | |
446 BoxedPrimitive); | |
447 s << INDENT << "arguments[" << i << "].l = __java_" << argument->indexedName() << ";" << endl; | |
448 } | |
449 s << INDENT << "qtjambi_call_java_signal(__jni_env, m_signals[" << pos << "], arguments);" | |
450 << endl; | |
451 | |
452 s << INDENT << "__jni_env->PopLocalFrame(0);" << endl; | |
453 | |
454 if (signal->type() != 0) | |
455 s << INDENT << default_return_statement_qt(signal->type()) << ";" << endl; | |
456 } | |
457 s << "}" << endl << endl; | |
458 | |
459 if (signal->implementingClass() == signal->ownerClass()) | |
460 writeFinalFunction(s, signal, cls); | |
461 } | |
462 | |
463 bool CppImplGenerator::hasCustomDestructor(const AbstractMetaClass *java_class) const | |
464 { | |
465 return !java_class->isQObject() && !java_class->typeEntry()->isValue(); | |
466 } | |
467 | |
468 void CppImplGenerator::writeInterfaceCasts(QTextStream &s, const AbstractMetaClass *java_class) | |
469 { | |
470 // pointers to native interface objects for classes that implement interfaces | |
471 // initializing | |
472 AbstractMetaClassList interfaces = java_class->interfaces(); | |
473 if (!interfaces.isEmpty()) { | |
474 for (int i=0; i<interfaces.size(); ++i) { | |
475 AbstractMetaClass *iface = interfaces.at(i); | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
476 |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
477 // in case of renamed class |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
478 InterfaceTypeEntry *ite = static_cast<InterfaceTypeEntry*>(iface->typeEntry()); |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
479 QString real_name = ite->origin()->qualifiedCppName(); |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
480 |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
481 s << "extern \"C\" DLL_PUBLIC " << real_name << "* qtd_" << java_class->name() << "_cast_to_" << iface->qualifiedCppName() |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
482 << "(" << java_class->qualifiedCppName() << " *ptr)" << endl << "{" << endl; |
1 | 483 Indentation indent(INDENT); |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
484 s << INDENT << "return dynamic_cast<" << real_name << "*>(ptr);" << endl; |
1 | 485 s << "}" << endl << endl; |
486 } | |
487 } | |
488 } | |
489 | |
490 void CppImplGenerator::writeInitCallbacks(QTextStream &s, const AbstractMetaClass *java_class) | |
491 { | |
492 QString initArgs = "pfunc_abstr *virts"; | |
493 if (java_class->isQObject()) | |
494 initArgs += ", pfunc_abstr *sigs, pfunc_abstr qobj_del"; | |
495 | |
496 s << "extern \"C\" DLL_PUBLIC void qtd_" << java_class->name() | |
497 << QString("_initCallBacks(%1) {").arg(initArgs) << endl; | |
498 | |
499 // virtual functions handlers | |
500 AbstractMetaFunctionList virtualFunctions = java_class->virtualFunctions(); | |
501 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { | |
502 const AbstractMetaFunction *function = virtualFunctions.at(pos); | |
503 if (!notWrappedYet(function)) { // qtd2 | |
504 s << " " << function->marshalledName() << "_dispatch = " | |
505 "(pf" << function->marshalledName() << "_dispatch) virts[" << pos << "];" << endl; | |
506 } | |
507 } | |
508 // D-side signal callbacks | |
303 | 509 if (java_class->isQObject()) { |
510 s << " qtd_" << java_class->name() << "_qt_metacall_dispatch = (QtMetacallCallback)sigs[0];" << endl | |
511 << " qtd_" << java_class->name() << "_metaObject_dispatch = (MetaObjectCallback)sigs[1];" << endl; | |
512 } | |
1 | 513 s << "}" << endl; |
514 } | |
515 | |
516 | |
517 void CppImplGenerator::write(QTextStream &s, const AbstractMetaClass *java_class) | |
518 { | |
519 | |
520 bool shellClass = java_class->generateShellClass(); | |
521 | |
522 // Includes | |
523 writeExtraIncludes(s, java_class); | |
524 bool shellInclude = (java_class->generateShellClass() | |
525 || java_class->queryFunctions(AbstractMetaClass::Signals | AbstractMetaClass::Visible | AbstractMetaClass::NotRemovedFromShell).size() > 0); | |
526 | |
527 // need to include QPainter for all widgets... | |
528 { | |
529 const AbstractMetaClass *qwidget = java_class; | |
530 while (qwidget && qwidget->name() != "QWidget") { | |
531 qwidget = qwidget->baseClass(); | |
532 } | |
533 if (qwidget) | |
534 s << "#include <QPainter>" << endl << endl; | |
535 } | |
536 /* | |
537 #if defined(QTJAMBI_DEBUG_TOOLS) | |
538 s << "#include <qtjambidebugtools_p.h>" << endl << endl; | |
539 #endif | |
540 */ | |
541 if (shellInclude) | |
542 s << "#include \"" << java_class->name() << "_shell" << ".h\"" << endl; | |
543 /* qtd | |
544 if (java_class->isQObject()) | |
545 s << "#include <qtdynamicmetaobject.h>" << endl; | |
546 */ | |
253 | 547 if (java_class->isQObject()) |
548 s << "#include <QObjectEntity.h>" << endl; | |
549 | |
1 | 550 s << "#include <iostream>" << endl; |
253 | 551 |
552 | |
553 | |
1 | 554 Include inc = java_class->typeEntry()->include(); |
555 if (!inc.name.isEmpty()) { | |
556 s << "#include "; | |
557 if (inc.type == Include::IncludePath) | |
558 s << "<"; | |
559 else | |
560 s << "\""; | |
561 s << inc.name; | |
562 if (inc.type == Include::IncludePath) | |
563 s << ">"; | |
564 else | |
565 s << "\""; | |
566 s << endl; | |
567 } | |
568 s << endl; // qtd | |
569 s << "#include \"qtd_core.h\"" << endl | |
570 << "#include \"ArrayOpsPrimitive.h\"" << endl | |
571 << "#include \"ArrayOps_qt_core.h\"" << endl; | |
572 | |
573 // qtd2 hack!! | |
37 | 574 if (java_class->package() == "qt.svg") |
1 | 575 s << "#include \"ArrayOps_qt_gui.h\"" << endl; |
576 | |
35 | 577 QString pkg_name = QString(java_class->package()).replace(".", "_"); |
578 s << QString("#include \"ArrayOps_%1.h\"").arg(pkg_name) << endl; | |
579 | |
1 | 580 s << endl; |
581 | |
582 writeInterfaceCasts(s, java_class); | |
583 | |
584 /* qtd2 | |
585 writeShellSignatures(s, java_class); | |
586 | |
587 writeDefaultConstructedValues(s, java_class); | |
588 | |
589 if (hasCustomDestructor(java_class)) */ | |
253 | 590 if (!java_class->isQObject()) |
591 writeFinalDestructor(s, java_class); | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
592 |
288 | 593 if (java_class->isQObject()) { |
594 writeQObjectEntity(s, java_class); | |
107 | 595 writeSignalsHandling(s, java_class); |
288 | 596 } |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
597 if (shellClass) { |
1 | 598 foreach (AbstractMetaFunction *function, java_class->functions()) { |
599 if (function->isConstructor() && !function->isPrivate()) | |
600 writeShellConstructor(s, function); | |
601 } | |
602 writeShellDestructor(s, java_class); | |
603 | |
253 | 604 if (!java_class->isQObject() && java_class->hasVirtualFunctions()) |
605 writeQtdEntityFunction(s, java_class); | |
1 | 606 |
607 if (java_class->isQObject()) | |
608 writeQObjectFunctions(s, java_class); | |
609 | |
610 // Virtual overrides | |
611 s << "// Virtual overrides" << endl; | |
612 AbstractMetaFunctionList virtualFunctions = java_class->virtualFunctions(); | |
613 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { | |
614 const AbstractMetaFunction *function = virtualFunctions.at(pos); | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
615 // qtd writeShellFunction(s, function, java_class, pos); |
1 | 616 writeShellVirtualFunction(s, function, java_class, pos); |
617 } | |
618 | |
619 if (cpp_shared) | |
620 writeInitCallbacks(s, java_class); | |
621 | |
622 // Functions in shell class | |
623 s << "// Functions in shell class" << endl; | |
624 AbstractMetaFunctionList shellFunctions = java_class->nonVirtualShellFunctions(); | |
625 for (int i=0; i<shellFunctions.size(); ++i) { | |
626 const AbstractMetaFunction *function = shellFunctions.at(i); | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
627 writeShellFunction(s, function, java_class, -1); |
1 | 628 } |
629 | |
630 // Write public overrides for functions that are protected in the base class | |
631 // so they can be accessed from the native callback | |
632 s << "// public overrides for functions that are protected in the base class" << endl; | |
633 AbstractMetaFunctionList public_override_functions = java_class->publicOverrideFunctions(); | |
634 foreach (AbstractMetaFunction *function, public_override_functions) { | |
635 if(notWrappedYet(function)) | |
636 continue; | |
637 writePublicFunctionOverride(s, function, java_class); | |
638 } | |
639 | |
640 // Write virtual function overries used to decide on static/virtual calls | |
641 s << "// Write virtual function overries used to decide on static/virtual calls" << endl; | |
642 AbstractMetaFunctionList virtual_functions = java_class->virtualOverrideFunctions(); | |
643 foreach (const AbstractMetaFunction *function, virtual_functions) { | |
644 if(notWrappedYet(function)) | |
645 continue; | |
646 writeVirtualFunctionOverride(s, function, java_class); | |
647 } | |
648 } | |
649 | |
650 writeExtraFunctions(s, java_class); | |
651 /* qtd2 | |
652 writeToStringFunction(s, java_class); | |
653 | |
654 if (java_class->hasCloneOperator()) { | |
655 writeCloneFunction(s, java_class); | |
656 } | |
270 | 657 */ |
658 // Signals emitters | |
272 | 659 AbstractMetaFunctionList signal_functions = signalFunctions(java_class, false); |
1 | 660 for (int i=0; i<signal_functions.size(); ++i) |
270 | 661 { |
662 const AbstractMetaFunction *function = signal_functions.at(i); | |
663 if(!function->isPrivate()) | |
664 writeFinalFunction(s, signal_functions.at(i), java_class); | |
665 } | |
1 | 666 s << "// ---externC---" << endl; |
667 | |
668 // Native callbacks (all java functions require native callbacks) | |
669 AbstractMetaFunctionList class_funcs = java_class->functionsInTargetLang(); | |
670 foreach (AbstractMetaFunction *function, class_funcs) { | |
671 if (!function->isEmptyFunction()) | |
672 writeFinalFunction(s, function, java_class); | |
673 } | |
674 s << "// ---externC---end" << endl; | |
675 | |
676 | |
677 class_funcs = java_class->queryFunctions(AbstractMetaClass::NormalFunctions | AbstractMetaClass::AbstractFunctions | AbstractMetaClass::NotRemovedFromTargetLang); | |
678 foreach (AbstractMetaFunction *function, class_funcs) { | |
679 if (function->implementingClass() != java_class) { | |
680 writeFinalFunction(s, function, java_class); | |
681 } | |
682 } | |
683 | |
684 // Field accessors | |
685 s << "// Field accessors" << endl; | |
686 foreach (AbstractMetaField *field, java_class->fields()) { | |
687 if (field->wasPublic() || (field->wasProtected() && !java_class->isFinal())) | |
688 writeFieldAccessors(s, field); | |
689 } | |
690 /* | |
691 s << "// writeFromNativeFunction" << endl; | |
692 writeFromNativeFunction(s, java_class); | |
693 | |
694 if (java_class->isQObject()) | |
695 writeOriginalMetaObjectFunction(s, java_class); | |
696 | |
697 if (java_class->typeEntry()->isValue()) | |
698 writeFromArrayFunction(s, java_class); | |
699 | |
700 // generate the __qt_cast_to_Xxx functions | |
701 if (!java_class->isNamespace() && !java_class->isInterface()) { | |
702 AbstractMetaClassList interfaces = java_class->interfaces(); | |
703 foreach (AbstractMetaClass *iface, interfaces) | |
704 writeInterfaceCastFunction(s, java_class, iface); | |
705 } | |
706 | |
707 writeSignalInitialization(s, java_class); | |
708 */ | |
709 // qtd writeJavaLangObjectOverrideFunctions(s, java_class); | |
710 | |
292 | 711 if (java_class->typeEntry()->isValue()) |
712 writeValueFunctions(s, java_class); | |
713 | |
253 | 714 if (java_class->isQObject()) |
715 { | |
716 s << endl << endl | |
717 << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_staticMetaObject() {" << endl | |
718 << " return (void*)&" << java_class->name() << "::staticMetaObject;" << endl | |
719 << "}" << endl; | |
720 } | |
721 | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
722 if (java_class->typeEntry()->isValue()) |
293 | 723 { |
724 { | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
725 QString argName = "orig"; |
293 | 726 s << endl << endl |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
727 << "extern \"C\" DLL_PUBLIC void qtd_" << java_class->name() << "_placed_copy(void* " |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
728 << argName << ", void* place) {" << endl |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
729 << QString(" const %1& __qt_%2 = (const %1& ) *(%1 *)%2;").arg(shellClassName(java_class)).arg(argName) << endl |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
730 << QString(" %1 *result = new (place) %1 (__qt_%2);").arg(java_class->qualifiedCppName()).arg(argName) << endl; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
731 // writeFinalConstructor(s, ctor, "result", "original", "(place)"); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
732 s << "}"; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
733 |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
734 s << endl << endl |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
735 << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_native_copy(void* " << argName << ") {" << endl |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
736 << QString(" const %1& __qt_%2 = (const %1& ) *(%1 *)%2;").arg(shellClassName(java_class)).arg(argName) << endl |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
737 << QString(" %1 *result = new %1 (__qt_%2);").arg(java_class->qualifiedCppName()).arg(argName) << endl |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
738 << " return result;" << endl; |
293 | 739 s << "}"; |
740 } | |
741 } | |
742 | |
1 | 743 s << endl << endl; |
744 | |
238 | 745 priGenerator->addSource(java_class->package(), fileNameForClass(java_class)); |
1 | 746 } |
747 | |
292 | 748 void CppImplGenerator::writeValueFunctions(QTextStream &s, const AbstractMetaClass *java_class) |
749 { | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
750 s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isComplex() { return (bool) QTypeInfo<%2>::isComplex; }\n").arg(java_class->name()).arg(java_class->qualifiedCppName()); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
751 s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isStatic() { return (bool) QTypeInfo<%2>::isStatic; }\n").arg(java_class->name()).arg(java_class->qualifiedCppName()); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
752 s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isLarge() { return (bool) QTypeInfo<%2>::isLarge; }\n").arg(java_class->name()).arg(java_class->qualifiedCppName()); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
753 s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isPointer() { return (bool) QTypeInfo<%2>::isPointer; }\n").arg(java_class->name()).arg(java_class->qualifiedCppName()); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
754 s << QString("extern \"C\" DLL_PUBLIC bool qtd_%1_QTypeInfo_isDummy() { return (bool) QTypeInfo<%2>::isDummy; }\n").arg(java_class->name()).arg(java_class->qualifiedCppName()); |
292 | 755 } |
756 | |
1 | 757 void CppImplGenerator::writeVirtualDispatchFunction(QTextStream &s, const AbstractMetaFunction *function, bool d_export) |
758 { | |
759 uint options2 = ReturnType | ExternC; | |
760 QString return_type = jniReturnName(function, options2); | |
761 QString f_name = function->marshalledName() + "_dispatch"; | |
762 | |
763 if(!d_export) | |
764 s << "extern \"C\" "; | |
765 | |
766 if (!cpp_shared || d_export) { | |
767 s << return_type << " " << f_name; | |
768 writeVirtualDispatchArguments(s, function, d_export); | |
769 if(!d_export) | |
770 s << ";"; | |
771 } else if (cpp_shared) { | |
772 s << "typedef " << return_type << " " << "(*pf" << f_name << ")"; | |
773 writeVirtualDispatchArguments(s, function, false); | |
774 s << ";" << endl | |
148
ae34188ddd84
private signals of QAbstractItemModel are now accessible
eldar
parents:
132
diff
changeset
|
775 << "pf" << f_name << " " << f_name << ";"; |
1 | 776 } |
777 | |
778 s << endl; | |
779 } | |
780 | |
781 void CppImplGenerator::writeShellVirtualFunction(QTextStream &s, const AbstractMetaFunction *function, | |
782 const AbstractMetaClass *implementor, int id) | |
783 { | |
784 // ---------------------------- | |
785 if(notWrappedYet(function)) | |
786 return; | |
787 | |
788 AbstractMetaType *f_type = function->type(); | |
789 QString new_return_type = function->typeReplaced(0); | |
790 bool has_function_type = ((f_type != 0 | |
791 || !new_return_type.isEmpty()) | |
792 && new_return_type != "void"); | |
793 | |
794 writeVirtualDispatchFunction(s, function); | |
795 | |
796 writeFunctionSignature(s, function, implementor, QString(), OriginalName); | |
797 | |
798 s << endl | |
799 << "{" << endl; | |
800 | |
801 Option options = NoOption; | |
802 | |
803 Indentation indent(INDENT); | |
804 //bool static_call = !(options & VirtualCall); | |
805 //s << "std::cout << \"entering " << function->marshalledName() << " \\n\"; " << endl; | |
806 | |
807 if (f_type) { | |
808 if (f_type->isTargetLangString()) | |
104 | 809 s << INDENT << "DArray ret_str;" << endl; |
81 | 810 |
1 | 811 if (f_type->name() == "QModelIndex") |
812 s << INDENT << "QModelIndexAccessor __d_return_value;" << endl; | |
81 | 813 else if (f_type->typeEntry()->isStructInD()) |
814 s << INDENT << f_type->typeEntry()->qualifiedCppName() << " __d_return_value;" << endl; | |
815 | |
1 | 816 if (f_type->isContainer()) |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
817 { |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
818 if (isNativeContainer(f_type)) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
819 { |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
820 s << INDENT; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
821 writeTypeInfo(s, f_type, ForceValueType); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
822 s << "__d_return_value;" << endl; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
823 } |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
824 else |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
825 s << INDENT << "void* __d_return_value;" << endl |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
826 << INDENT << "size_t __d_return_value_size;" << endl; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
827 } |
1 | 828 } |
829 | |
830 AbstractMetaArgumentList arguments = function->arguments(); | |
831 foreach (AbstractMetaArgument *argument, arguments) { | |
832 if (!function->argumentRemoved(argument->argumentIndex()+1)) { | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
833 AbstractMetaType *atype = argument->type(); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
834 if (!atype->isPrimitive() |
1 | 835 || !function->conversionRule(TypeSystem::NativeCode, argument->argumentIndex()+1).isEmpty()) { |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
836 if(atype->isContainer()) { |
1 | 837 QString arg_name = argument->indexedName(); |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
838 if(!isNativeContainer(atype)) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
839 writeQtToJava(s, |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
840 argument->type(), |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
841 arg_name, |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
842 "__d_" + arg_name, |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
843 function, |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
844 argument->argumentIndex() + 1, |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
845 Option(VirtualDispatch)); |
1 | 846 } |
847 } | |
848 } | |
849 } | |
850 | |
851 if ((options & NoReturnStatement) == 0) | |
852 s << INDENT; | |
853 /* qtd if (function->isAbstract() && static_call) { | |
854 s << default_return_statement_qt(function->type(), options) << ";" << endl; | |
855 } else */ | |
856 { | |
857 if (f_type) { | |
858 if (f_type->isTargetLangString() || f_type->isContainer()) | |
859 ; | |
860 else if ((f_type->isValue() && !f_type->typeEntry()->isStructInD()) || | |
861 f_type->isVariant() ) | |
862 s << f_type->name() << " *__qt_return_value = (" << f_type->name() << "*) "; | |
863 else if (f_type->isObject() || f_type->isQObject()) | |
864 s << "return (" << f_type->name() <<"*) "; | |
81 | 865 else if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) |
1 | 866 ; |
867 else if ((options & NoReturnStatement) == 0) | |
868 s << "return "; | |
869 | |
870 if (f_type->isEnum() || f_type->isFlags()) | |
871 s << "(" << f_type->typeEntry()->qualifiedCppName() <<") "; | |
872 } | |
873 | |
874 s << function->marshalledName() << "_dispatch(" | |
253 | 875 << "this->dId"; |
1 | 876 |
877 if (f_type) { | |
878 if (f_type->isTargetLangString()) | |
104 | 879 s << ", &ret_str"; |
81 | 880 if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
881 s << ", &__d_return_value"; // TODO should both be refactored into isNativeType function |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
882 if (f_type->isContainer()) { |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
883 if ( ((const ContainerTypeEntry *)f_type->typeEntry())->isQList() ) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
884 s << ", &__d_return_value"; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
885 else |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
886 s << ", &__d_return_value, &__d_return_value_size"; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
887 } |
1 | 888 } |
889 | |
890 if (function->arguments().size() > 0) | |
891 s << ", "; | |
892 writeFunctionCallArguments(s, function, QString(), Option(options | ForceEnumCast | SkipRemovedArguments | ExcludeConst | VirtualDispatch)); | |
893 | |
894 s << ");" << endl; | |
895 | |
896 //s << "std::cout << \"leaving " << function->marshalledName() << " \\n\"; " << endl; | |
897 | |
898 if (f_type) { | |
899 if (f_type->name() == "QModelIndex") { | |
900 s << INDENT << "QModelIndex __qt_return_value = qtd_to_QModelIndex( __d_return_value );" << endl; | |
901 #ifdef Q_OS_WIN32 | |
253 | 902 s << "qtd_dummy();" << endl; // hack!!! |
1 | 903 #endif |
904 s << INDENT << "return __qt_return_value;" << endl; | |
81 | 905 } else if (f_type->typeEntry()->isStructInD()) |
906 s << INDENT << "return __d_return_value;" << endl; | |
1 | 907 |
908 if (f_type->isContainer()) { | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
909 if (isNativeContainer(f_type)) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
910 s << INDENT << "return __d_return_value;" << endl; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
911 else |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
912 { |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
913 writeJavaToQt(s, f_type, "__qt_return_value", "__d_return_value", |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
914 function, 0, GlobalRefJObject); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
915 s << INDENT << "return __qt_return_value;" << endl; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
916 } |
1 | 917 } |
918 | |
919 if (f_type->isTargetLangString()) | |
104 | 920 s << INDENT << "return " << "QString::fromUtf8((const char*) ret_str.ptr, ret_str.length);" << endl; |
1 | 921 |
922 if ( ( f_type->isValue() && !f_type->typeEntry()->isStructInD() ) || f_type->isVariant() ) | |
923 s << INDENT << "return " << f_type->name() << "(*__qt_return_value);" << endl; //" __qt_return_value = "; | |
924 } | |
925 } | |
926 | |
927 s << "}" << endl << endl; | |
928 // ---------------------------- | |
929 } | |
930 | |
931 void CppImplGenerator::writeVirtualDispatchArguments(QTextStream &s, const AbstractMetaFunction *d_function, bool d_export) | |
932 { | |
933 uint nativeArgCount = 0; | |
934 AbstractMetaType *ret_type = d_function->type(); | |
935 | |
936 s << "(void *d_entity"; | |
937 | |
938 if (ret_type) { | |
104 | 939 if (ret_type->isTargetLangString()) { |
940 if (d_export) | |
941 s << ", string* ret_str"; | |
942 else | |
943 s << ", DArray* ret_str"; | |
944 } | |
1 | 945 if (ret_type->name() == "QModelIndex") |
946 s << ", QModelIndexAccessor *__d_return_value"; | |
81 | 947 else if(ret_type->typeEntry()->isStructInD()) |
948 s << ", " << ret_type->typeEntry()->qualifiedCppName() << " *__d_return_value"; | |
949 | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
950 if (ret_type->isContainer()) { |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
951 if(isNativeContainer(ret_type)) { |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
952 if(d_export) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
953 s << ", " << DGenerator::translateType(ret_type, d_function->ownerClass(), NoOption) << "* __d_arr"; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
954 else |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
955 s << ", void * __d_arr"; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
956 } |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
957 else |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
958 s << ", void** __d_arr_ptr, size_t* __d_arr_size"; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
959 } |
1 | 960 } |
961 | |
962 if (d_function->arguments().size() > 0) | |
963 s << ", "; | |
964 | |
965 | |
966 // the function arguments | |
967 AbstractMetaArgumentList arguments = d_function->arguments(); | |
968 foreach (const AbstractMetaArgument *argument, arguments) { | |
969 if (!d_function->argumentRemoved(argument->argumentIndex() + 1)) { | |
970 if (nativeArgCount > 0) | |
971 s << "," << " "; | |
972 | |
973 AbstractMetaType *d_type = argument->type(); | |
974 QString arg_name = argument->indexedName(); | |
975 | |
976 if (d_type->name() == "QModelIndex") | |
977 s << "QModelIndexAccessor" << QString(d_type->actualIndirections(), '*') << " " << arg_name; | |
978 else if (d_type->isContainer()) { | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
979 if ( isNativeContainer(d_type) ) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
980 s << "void* "; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
981 else if (d_export) |
1 | 982 s << DGenerator::translateType(d_type, d_function->ownerClass(), NoOption) << "* "; |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
983 else |
1 | 984 s << "DArray* "; |
985 s << arg_name; | |
986 } else if (d_type->typeEntry()->isStructInD()) | |
987 s << d_type->typeEntry()->qualifiedCppName() << QString(d_type->actualIndirections(), '*') | |
988 << " " << arg_name; | |
989 else if (d_type->isTargetLangString()) { | |
990 if (d_export) | |
991 s << "wchar* "; | |
992 else | |
993 s << "const unsigned short* "; | |
994 s << QString("%1, int %1_size").arg(arg_name); | |
995 } else { | |
996 if(d_type->isVariant()) | |
997 s << "void*"; | |
998 else if (!d_type->hasNativeId()) | |
999 { | |
1000 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_type->typeEntry()); | |
1001 if(d_type->typeEntry()->isObject() && ctype->isAbstract() && d_export) | |
1002 { | |
1003 QString d_name = d_type->typeEntry()->qualifiedCppName(); | |
1004 s << d_name + "_ConcreteWrapper" + QString(d_type->indirections(),'*'); | |
1005 } | |
1006 else | |
39 | 1007 s << translateType(d_type, EnumAsInts, d_export); |
1 | 1008 } |
1009 else | |
1010 s << "void*"; | |
1011 s << " " << argument->indexedName(); | |
1012 } | |
1013 nativeArgCount++; | |
1014 } | |
1015 } | |
1016 s << ")"; | |
1017 } | |
1018 | |
1019 void CppImplGenerator::writeJavaLangObjectOverrideFunctions(QTextStream &s, const AbstractMetaClass *cls) | |
1020 { | |
1021 if (cls->hasHashFunction()) { | |
1022 AbstractMetaFunctionList hashcode_functions = cls->queryFunctionsByName("hashCode"); | |
1023 bool found = false; | |
1024 foreach (const AbstractMetaFunction *function, hashcode_functions) { | |
1025 if (function->actualMinimumArgumentCount() == 0) { | |
1026 found = true; | |
1027 break; | |
1028 } | |
1029 } | |
1030 | |
1031 if (!found) { | |
1032 s << endl | |
1033 << INDENT << jni_function_signature(cls->package(), cls->name(), "__qt_hashCode", "jint") | |
1034 << "(JNIEnv *__jni_env, jobject, jlong __this_nativeId)" << endl | |
1035 << INDENT << "{" << endl; | |
1036 { | |
1037 Indentation indent(INDENT); | |
1038 s << INDENT << "Q_UNUSED(__jni_env);" << endl | |
1039 << INDENT << cls->qualifiedCppName() << " *__qt_this = (" | |
1040 << cls->qualifiedCppName() << " *) qtjambi_from_jlong(__this_nativeId);" << endl | |
1041 << INDENT << "QTJAMBI_EXCEPTION_CHECK(__jni_env);" << endl | |
1042 << INDENT << "Q_ASSERT(__qt_this);" << endl | |
1043 << INDENT << "return qHash(*__qt_this);" << endl; | |
1044 } | |
1045 s << INDENT << "}" << endl; | |
1046 } | |
1047 } | |
1048 | |
1049 // Qt has a standard toString() conversion in QVariant? | |
1050 QVariant::Type type = QVariant::nameToType(cls->qualifiedCppName().toLatin1()); | |
1051 if (QVariant(type).canConvert(QVariant::String) && !cls->hasToStringCapability()) { | |
1052 AbstractMetaFunctionList tostring_functions = cls->queryFunctionsByName("toString"); | |
1053 bool found = false; | |
1054 foreach (const AbstractMetaFunction *function, tostring_functions) { | |
1055 if (function->actualMinimumArgumentCount() == 0) { | |
1056 found = true; | |
1057 break; | |
1058 } | |
1059 } | |
1060 | |
1061 if (!found) { | |
1062 s << endl | |
1063 << INDENT << jni_function_signature(cls->package(), cls->name(), "__qt_toString", "jstring") | |
1064 << "(JNIEnv *__jni_env, jobject, jlong __this_nativeId)" << endl | |
1065 << INDENT << "{" << endl; | |
1066 { | |
1067 Indentation indent(INDENT); | |
1068 s << INDENT << cls->qualifiedCppName() << " *__qt_this = (" | |
1069 << cls->qualifiedCppName() << " *) qtjambi_from_jlong(__this_nativeId);" << endl | |
1070 << INDENT << "QTJAMBI_EXCEPTION_CHECK(__jni_env);" << endl | |
1071 << INDENT << "Q_ASSERT(__qt_this);" << endl | |
1072 << INDENT << "return qtjambi_from_qstring(__jni_env, QVariant(*__qt_this).toString());" << endl; | |
1073 } | |
1074 s << INDENT << "}" << endl; | |
1075 } | |
1076 } | |
1077 } | |
1078 | |
1079 void CppImplGenerator::writeExtraFunctions(QTextStream &s, const AbstractMetaClass *java_class) | |
1080 { | |
1081 const ComplexTypeEntry *class_type = java_class->typeEntry(); | |
1082 Q_ASSERT(class_type); | |
1083 | |
1084 CodeSnipList code_snips = class_type->codeSnips(); | |
1085 foreach (const CodeSnip &snip, code_snips) { | |
1086 if (snip.language == TypeSystem::ShellCode || snip.language == TypeSystem::NativeCode) { | |
1087 snip.formattedCode(s, INDENT) << endl; | |
1088 } | |
1089 } | |
1090 } | |
1091 | |
1092 void CppImplGenerator::writeToStringFunction(QTextStream &s, const AbstractMetaClass *java_class) | |
1093 { | |
1094 FunctionModelItem fun = java_class->hasToStringCapability(); | |
1095 bool core = java_class->package() == QLatin1String("qt.core"); | |
1096 bool qevent = false; | |
1097 | |
1098 const AbstractMetaClass *cls = java_class; | |
1099 while (cls) { | |
1100 if (cls->name() == "QEvent") { | |
1101 qevent = true; | |
1102 fun = cls->hasToStringCapability(); | |
1103 break; | |
1104 } | |
1105 cls = cls->baseClass(); | |
1106 } | |
1107 | |
1108 if (!java_class->hasDefaultToStringFunction() && fun && !(qevent && core)) { | |
1109 | |
1110 int indirections = fun->arguments().at(1)->type().indirections(); | |
1111 QString deref = QLatin1String(indirections == 0 ? "*" : ""); | |
1112 | |
1113 s << endl; | |
1114 s << "#include <QDebug>" << endl; | |
1115 s << jni_function_signature(java_class->package(), java_class->name(), "__qt_toString", "jstring") | |
1116 << "(JNIEnv *__jni_env, jobject, jlong __this_nativeId)" << endl | |
1117 << INDENT << "{" << endl; | |
1118 { | |
1119 Indentation indent(INDENT); | |
1120 s << INDENT << java_class->qualifiedCppName() << " *__qt_this = (" | |
1121 << java_class->qualifiedCppName() << " *) qtjambi_from_jlong(__this_nativeId);" << endl | |
1122 << INDENT << "QTJAMBI_EXCEPTION_CHECK(__jni_env);" << endl | |
1123 << INDENT << "Q_ASSERT(__qt_this);" << endl | |
1124 | |
1125 << INDENT << "QString res;" << endl | |
1126 << INDENT << "QDebug d(&res);" << endl | |
1127 << INDENT << "d << " << deref << "__qt_this;" << endl; | |
1128 s << INDENT << "return qtjambi_from_qstring(__jni_env, res);" << endl; | |
1129 } | |
1130 s << INDENT << "}" << endl << endl; | |
1131 } | |
1132 } | |
1133 | |
1134 void CppImplGenerator::writeCloneFunction(QTextStream &s, const AbstractMetaClass *java_class) | |
1135 { | |
1136 s << endl | |
1137 << jni_function_signature(java_class->package(), java_class->name(), "__qt_clone", "jobject") << endl | |
1138 << "(JNIEnv *__jni_env, jobject, jlong __this_nativeId)" << endl | |
1139 << INDENT << "{" << endl; | |
1140 { | |
1141 Indentation indent(INDENT); | |
1142 s << INDENT << java_class->qualifiedCppName() << " *__qt_this = (" | |
1143 | |
1144 << java_class->qualifiedCppName() << " *) qtjambi_from_jlong(__this_nativeId);" << endl | |
1145 << INDENT << "QTJAMBI_EXCEPTION_CHECK(__jni_env);" << endl | |
1146 << INDENT << "Q_ASSERT(__qt_this);" << endl | |
1147 << INDENT << java_class->qualifiedCppName() << " *res = __qt_this;" << endl | |
1148 << INDENT << "return qtjambi_from_object(__jni_env, res, \"" << java_class->name() << "\", \"" << java_class->package().replace(".", "/") << "/\", true);" << endl; | |
1149 } | |
1150 s << INDENT << "}" << endl << endl; | |
1151 } | |
1152 | |
1153 void CppImplGenerator::writeShellSignatures(QTextStream &s, const AbstractMetaClass *java_class) | |
1154 { | |
1155 bool has_constructors = java_class->hasConstructors(); | |
1156 | |
1157 // Write the function names... | |
1158 if (has_constructors && java_class->hasVirtualFunctions()) { | |
1159 AbstractMetaFunctionList virtual_functions = java_class->virtualFunctions(); | |
1160 { | |
1161 Indentation indent(INDENT); | |
1162 | |
1163 int pos = -1; | |
1164 foreach (AbstractMetaFunction *function, virtual_functions) { | |
1165 ++pos; | |
1166 | |
1167 if (pos == 0) | |
1168 s << "static const char *qtjambi_method_names[] = {"; | |
1169 else | |
1170 s << ","; | |
1171 s << endl | |
1172 << "/* " << QString("%1").arg(QString::number(pos), 3) << " */ " | |
1173 << "\"" << function->name() << "\""; | |
1174 } | |
1175 if (pos >= 0) | |
1176 s << endl << "};" << endl << endl; | |
1177 else | |
1178 s << "static const char **qtjambi_method_names = 0;" << endl; | |
1179 } | |
1180 | |
1181 // Write the function signatures | |
1182 { | |
1183 Indentation indent(INDENT); | |
1184 | |
1185 int pos = -1; | |
1186 foreach (AbstractMetaFunction *function, virtual_functions) { | |
1187 ++pos; | |
1188 | |
1189 if (pos == 0) | |
1190 s << "static const char *qtjambi_method_signatures[] = {"; | |
1191 else | |
1192 s << ","; | |
1193 s << endl | |
1194 << "/* " << QString("%1").arg(QString::number(pos), 3) << " */ " | |
1195 << "\"" | |
1196 << jni_signature(function, SlashesAndStuff) | |
1197 << "\""; | |
1198 } | |
1199 if (pos >= 0) | |
1200 s << endl << "};" << endl; | |
1201 else | |
1202 s << "static const char **qtjambi_method_signatures = 0;" << endl; | |
1203 s << "static const int qtjambi_method_count = " << QString::number(pos + 1) << ";" << endl | |
1204 << endl; | |
1205 } | |
1206 } | |
1207 | |
1208 if (has_constructors && java_class->hasInconsistentFunctions()) { | |
1209 AbstractMetaFunctionList inconsistents = java_class->cppInconsistentFunctions(); | |
1210 // Write the inconsistent function names... | |
1211 { | |
1212 Indentation indent(INDENT); | |
1213 s << "static const char *qtjambi_inconsistent_names[] = {"; | |
1214 for (int i=0; i<inconsistents.size(); ++i) { | |
1215 if (i != 0) | |
1216 s << ","; | |
1217 s << endl << INDENT << "\"" << inconsistents.at(i)->name() << "\""; | |
1218 } | |
1219 s << endl << "};" << endl << endl; | |
1220 } | |
1221 | |
1222 // Write the function signatures | |
1223 { | |
1224 Indentation indent(INDENT); | |
1225 s << "static const char *qtjambi_inconsistent_signatures[] = {"; | |
1226 for (int i=0; i<inconsistents.size(); ++i) { | |
1227 const AbstractMetaFunction *function = inconsistents.at(i); | |
1228 | |
1229 if (i != 0) | |
1230 s << ","; | |
1231 s << endl << INDENT << "\"" | |
1232 << jni_signature(function, SlashesAndStuff) | |
1233 << "\""; | |
1234 } | |
1235 s << endl << "};" << endl << endl; | |
1236 } | |
1237 s << "static const int qtjambi_inconsistent_count = " << inconsistents.size() << ";" << endl | |
1238 << endl; | |
1239 } | |
1240 | |
1241 | |
1242 AbstractMetaFunctionList signal_functions = java_class->cppSignalFunctions(); | |
1243 if (signal_functions.size()) { | |
1244 Indentation indent(INDENT); | |
1245 s << "static const char *qtjambi_signal_names[] = {"; | |
1246 for (int i=0; i<signal_functions.size(); ++i) { | |
1247 if (i != 0) | |
1248 s << ","; | |
1249 | |
1250 const AbstractMetaFunction *f = signal_functions.at(i); | |
1251 | |
1252 QString signalName = f->name(); | |
1253 | |
1254 s << endl << INDENT << "\"" << signalName << "\""; | |
1255 } | |
1256 s << endl << "};" << endl << endl; | |
1257 | |
1258 s << "static const int qtjambi_signal_argumentcounts[] = {"; | |
1259 for (int i=0; i<signal_functions.size(); ++i) { | |
1260 if (i != 0) | |
1261 s << ","; | |
1262 s << endl << INDENT << signal_functions.at(i)->arguments().count(); | |
1263 } | |
1264 s << endl << "};" << endl << endl; | |
1265 s << "static const int qtjambi_signal_count = " << signal_functions.size() << ";" << endl | |
1266 << endl; | |
1267 } | |
1268 } | |
1269 | |
253 | 1270 void CppImplGenerator::writeQObjectEntity(QTextStream &s, const AbstractMetaClass *java_class) |
1271 { | |
1272 QString entityName = java_class->name() + "Entity"; | |
1273 QString className = java_class->name(); | |
1274 | |
1275 s << "class " << entityName << " : public QObject, public QtD_QObjectEntity" << endl | |
1276 << "{" << endl | |
1277 << "public:" << endl | |
1278 << " Q_OBJECT_CHECK" << endl | |
288 | 1279 << "// virtual int qt_metacall(QMetaObject::Call, int, void **);" << endl << endl |
253 | 1280 |
1281 << " " << entityName << "(QObject *qObject, void *dId) : QObject(), QtD_QObjectEntity(qObject, dId) {}" << endl | |
1282 << "};" << endl << endl; | |
1283 | |
288 | 1284 /* // QObject_Link::qt_metacall() |
253 | 1285 s << "int " << entityName << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl |
1286 << "{" << endl | |
1287 << " _id = QObject::qt_metacall(_c, _id, _a);" << endl | |
1288 << " if (_id < 0 || _c != QMetaObject::InvokeMetaMethod)" << endl | |
1289 << " return _id;" << endl | |
1290 << " emit_callbacks_" << java_class->name() << "[_id](dId, _a);" << endl | |
1291 << " return -1;" << endl | |
1292 << "}" << endl << endl; | |
288 | 1293 */ |
253 | 1294 s << "extern \"C\" DLL_PUBLIC void qtd_" << className << "_createEntity(void *nativeId, void* dId)" << endl |
1295 << "{" << endl | |
1296 << " new " << entityName << "((QObject*)nativeId, dId);" << endl | |
1297 << "}" << endl << endl; | |
1298 } | |
1299 | |
1 | 1300 void CppImplGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *java_class) |
1301 { | |
1302 // QObject::metaObject() | |
1303 /* s << "const QMetaObject *" << shellClassName(java_class) << "::metaObject() const" << endl | |
1304 << "{" << endl | |
1305 << " if (m_meta_object == 0) {" << endl | |
1306 << " JNIEnv *__jni_env = qtjambi_current_environment();" << endl | |
1307 << " jobject __obj = m_link != 0 ? m_link->javaObject(__jni_env) : 0;" << endl | |
1308 << " if (__obj == 0) return " << java_class->qualifiedCppName() << "::metaObject();" << endl | |
1309 << " else m_meta_object = qtjambi_metaobject_for_class(__jni_env, __jni_env->GetObjectClass(__obj), " << java_class->qualifiedCppName() << "::metaObject());" << endl; | |
1310 | |
1311 | |
1312 AbstractMetaFunctionList virtualFunctions = java_class->virtualFunctions(); | |
1313 for (int pos=0; pos<virtualFunctions.size(); ++pos) { | |
1314 const AbstractMetaFunction *virtualFunction = virtualFunctions.at(pos); | |
1315 if (virtualFunction->isVirtualSlot()) { | |
1316 QStringList introspectionCompatibleSignatures = virtualFunction->introspectionCompatibleSignatures(); | |
1317 foreach (QString introspectionCompatibleSignature, introspectionCompatibleSignatures) { | |
1318 s << " {" << endl | |
1319 << " int idx = " | |
1320 << java_class->qualifiedCppName() << "::metaObject()->indexOfMethod(\"" | |
1321 << introspectionCompatibleSignature << "\");" << endl; | |
1322 | |
1323 s << " if (idx >= 0) m_map.insert(idx, " << pos << ");" << endl | |
1324 << " }" << endl; | |
1325 } | |
1326 } | |
1327 | |
1328 } | |
1329 | |
1330 s << " }" << endl | |
1331 << " return m_meta_object;" << endl | |
1332 << "}" << endl << endl; | |
1333 | |
1334 // QObject::qt_metacast() | |
1335 s << "void *" << shellClassName(java_class) << "::qt_metacast(const char *_clname)" << endl | |
1336 << "{" << endl | |
1337 << " if (!_clname) return 0;" << endl | |
1338 << " if (!strcmp(_clname, \"" << shellClassName(java_class) << "\"))" << endl | |
1339 << " return static_cast<void*>(const_cast<" << shellClassName(java_class) << "*>(this));" << endl | |
1340 << " return " << java_class->qualifiedCppName() << "::qt_metacast(_clname);" << endl | |
1341 << "}" << endl << endl; | |
1342 */ | |
288 | 1343 /* |
1 | 1344 s << "int " << shellClassName(java_class) << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl |
288 | 1345 << "{" << endl |
1346 << " _id = " << java_class->qualifiedCppName() << "::qt_metacall(_c, _id, _a);" << endl | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
1347 << " if (_id < 0 || _c != QMetaObject::InvokeMetaMethod)" << endl |
253 | 1348 << " return _id;" << endl |
1349 << " emit_callbacks_" << java_class->name() << "[_id](this->dId, _a);" << endl | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
1350 << " return -1;" << endl |
1 | 1351 << "}" << endl << endl; |
288 | 1352 */ |
1353 | |
301 | 1354 if(cpp_shared) |
303 | 1355 s << "MetaObjectCallback qtd_" << java_class->name() << "_metaObject_dispatch;" << endl |
1356 << "QtMetacallCallback qtd_" << java_class->name() << "_qt_metacall_dispatch;" << endl; | |
301 | 1357 else |
303 | 1358 s << "extern \"C\" const QMetaObject* qtd_" << java_class->name() << "_metaObject_dispatch(void *d_entity);" << endl |
1359 << "extern \"C\" int qtd_" << java_class->name() << "_qt_metacall_dispatch(void *d_entity, QMetaObject::Call _c, int _id, void **_a);" << endl; | |
1360 | |
1361 s << endl | |
1362 << "const QMetaObject * " << shellClassName(java_class) << "::metaObject() const" << endl | |
1363 << "{" << endl | |
1364 << " return qtd_" << java_class->name() << "_metaObject_dispatch(this->dId);" << endl | |
1365 << "}" << endl << endl | |
1366 << "int " << shellClassName(java_class) << "::qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl | |
288 | 1367 << "{" << endl |
1368 << " return qtd_" << java_class->name() << "_qt_metacall_dispatch(this->dId, _c, _id, _a);" << endl | |
1369 << "}" << endl << endl | |
1370 | |
1371 << "int " << shellClassName(java_class) << "::__override_qt_metacall(QMetaObject::Call _c, int _id, void **_a)" << endl | |
1372 << "{" << endl | |
1373 << " return " << java_class->qualifiedCppName() << "::qt_metacall(_c, _id, _a);" | |
1374 << "}" << endl << endl | |
1375 | |
1376 << "extern \"C\" DLL_PUBLIC int qtd_" << java_class->name() << "_qt_metacall(void* __this_nativeId, QMetaObject::Call _c, int _id, void **_a)" | |
1377 << "{" << endl | |
1378 << " " << shellClassName(java_class) << " *__qt_this = (" << shellClassName(java_class) << " *) __this_nativeId;" << endl | |
1379 << " return __qt_this->__override_qt_metacall(_c, _id, _a);" << endl | |
1380 << "}" << endl << endl; | |
1 | 1381 } |
1382 | |
270 | 1383 void CppImplGenerator::writeSignalEmitter(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunction *function) |
1 | 1384 { |
270 | 1385 Q_ASSERT(d_class); |
1386 | |
1387 if (function->isModifiedRemoved(TypeSystem::NativeCode)) | |
1388 return; | |
1389 | |
1390 const AbstractMetaClass *cls = d_class ? d_class : function->ownerClass(); | |
1391 | |
1392 QString function_signature = cls->name() + "::" + function->signature(); | |
1393 | |
1394 s << "// " << function_signature << endl; | |
1395 | |
1396 const QString qt_object_name = function->isStatic() ? shellClassName(cls) : "__qt_this"; | |
1397 | |
1398 // we are not wrapping some functions depending on arguments because API is not yet full | |
1399 if (notWrappedYet(function)) | |
1400 return; | |
1401 | |
1402 // function signature... | |
1403 bool callThrough = function->needsCallThrough(); | |
1404 // uint options = m_native_jump_table ? ReturnType | ExternC : StandardJNISignature; | |
1405 writeFunctionName(s, function, cls, ExternC); | |
1406 s << endl; | |
1407 writeFinalFunctionArguments(s, function); | |
1408 s << endl << "{" << endl; | |
1 | 1409 Indentation indent(INDENT); |
1410 | |
270 | 1411 writeFinalFunctionSetup(s, function, qt_object_name, cls); |
1412 | |
1413 s << "void *args[] = {NULL"; | |
1414 // create an array of pointers to args | |
1415 /* AbstractMetaArgumentList arguments = java_function->arguments(); | |
1416 foreach (const AbstractMetaArgument *argument, arguments) { | |
1417 s << ", "; | |
1418 if (!argument->type()->isPrimitive() | |
1419 || !java_function->conversionRule(TypeSystem::NativeCode, argument->argumentIndex() + 1).isEmpty()) { | |
1420 // s << &qt_arg + n | |
1 | 1421 } |
1422 } | |
270 | 1423 */ |
1424 s << endl << "}"; | |
1425 s << endl << endl; | |
1 | 1426 } |
1427 | |
1428 void CppImplGenerator::writeSignalsHandling(QTextStream &s, const AbstractMetaClass *java_class) | |
1429 { | |
288 | 1430 return; // #TODO probably don't need this function at all |
1431 | |
1 | 1432 s << "extern \"C\" typedef void (*EmitCallback)(void*, void**);" << endl; |
1433 AbstractMetaFunctionList signal_funcs = signalFunctions(java_class); | |
1434 | |
1435 if (cpp_shared) | |
132 | 1436 if(signal_funcs.size() > 0) |
1437 s << "EmitCallback emit_callbacks_" << java_class->name() << "[" << signal_funcs.size() << "];" << endl; | |
1438 else | |
1439 s << "EmitCallback emit_callbacks_" << java_class->name() << "[1];" << endl; // Hack for msvc. | |
1 | 1440 else { |
1441 // D-side signal callbacks | |
1442 for(int i = 0; i < signal_funcs.size(); i++) { | |
1443 AbstractMetaFunction *signal = signal_funcs.at(i); | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
148
diff
changeset
|
1444 s << "extern \"C\" DLL_PUBLIC void " << signalExternName(java_class, signal) << "_handle(void* d_entity, void** args);" << endl; |
1 | 1445 } |
1446 | |
132 | 1447 if(signal_funcs.size() > 0) |
1448 s << "EmitCallback emit_callbacks_" << java_class->name() << "[" << signal_funcs.size() << "] = {" << endl; | |
1449 else | |
1450 s << "EmitCallback emit_callbacks_" << java_class->name() << "[1] = {" << endl; // Hack for msvc. | |
1 | 1451 for(int i = 0; i < signal_funcs.size(); i++) { |
1452 AbstractMetaFunction *signal = signal_funcs.at(i); | |
1453 s << endl; | |
1454 if (i != 0) | |
1455 s << ", "; | |
1456 s << "&" << signalExternName(java_class, signal) << "_handle"; | |
1457 } | |
1458 s << endl << "};" << endl << endl; | |
1459 } | |
1460 } | |
1461 | |
1462 | |
1463 void CppImplGenerator::writeShellConstructor(QTextStream &s, const AbstractMetaFunction *java_function) | |
1464 { | |
1465 if (java_function->isModifiedRemoved(TypeSystem::ShellCode)) | |
1466 return; | |
1467 | |
1468 const AbstractMetaClass *cls = java_function->ownerClass(); | |
1469 AbstractMetaArgumentList arguments = java_function->arguments(); | |
1470 | |
1471 writeFunctionSignature(s, java_function, cls); | |
1472 | |
1473 s << endl; | |
1474 s << " : " << cls->qualifiedCppName() << "("; | |
1475 for (int i=0; i<arguments.size(); ++i) { | |
1476 s << arguments.at(i)->indexedName(); | |
1477 if (i != arguments.size() - 1) | |
1478 s << ", "; | |
1479 } | |
1480 s << ")"; | |
253 | 1481 if (cls->isQObject()) |
1482 s << "," << endl << " QtD_QObjectEntity(this, d_ptr)"; | |
1483 else if (cls->hasVirtualFunctions()) | |
1484 s << "," << endl << " QtD_Entity(d_ptr)"; | |
1 | 1485 /* qtd s << " m_meta_object(0)," << endl; |
1486 s << " m_vtable(0)," << endl | |
1487 << " m_link(0)" << endl; | |
1488 */ | |
1489 s << endl; | |
1490 s << "{" << endl; | |
1491 { | |
1492 Indentation indent(INDENT); | |
253 | 1493 |
1 | 1494 writeCodeInjections(s, java_function, cls, CodeSnip::Beginning, TypeSystem::ShellCode); |
1495 writeCodeInjections(s, java_function, cls, CodeSnip::End, TypeSystem::ShellCode); | |
1496 } | |
1497 s << "}" << endl << endl; | |
1498 } | |
1499 | |
1500 void CppImplGenerator::writeShellDestructor(QTextStream &s, const AbstractMetaClass *java_class) | |
1501 { | |
1502 s << shellClassName(java_class) << "::~" | |
1503 << shellClassName(java_class) << "()" << endl | |
1504 << "{" << endl; | |
1505 { | |
253 | 1506 //s << " std::cout << \"In shell destructor of " << java_class->name() << ", nativeId: \" << this << std::endl;"; |
1507 if (java_class->isQObject()) | |
1508 s << " destroyEntity(this);"; | |
1 | 1509 } |
1510 s << "}" << endl << endl; | |
1511 } | |
1512 | |
1513 void CppImplGenerator::writeCodeInjections(QTextStream &s, const AbstractMetaFunction *java_function, | |
1514 const AbstractMetaClass *implementor, CodeSnip::Position position, | |
1515 TypeSystem::Language language) | |
1516 { | |
1517 | |
1518 FunctionModificationList mods; | |
1519 const AbstractMetaClass *cls = implementor; | |
1520 while (cls != 0) { | |
1521 mods += java_function->modifications(cls); | |
1522 | |
1523 if (cls == cls->baseClass()) | |
1524 break; | |
1525 cls = cls->baseClass(); | |
1526 } | |
1527 | |
1528 foreach (FunctionModification mod, mods) { | |
1529 if (mod.snips.count() <= 0) | |
1530 continue ; | |
1531 | |
1532 foreach (CodeSnip snip, mod.snips) { | |
1533 if (snip.position != position) | |
1534 continue ; | |
1535 | |
1536 if ((snip.language & language) == false) | |
1537 continue ; | |
1538 | |
1539 if (position == CodeSnip::End) | |
1540 s << endl; | |
1541 | |
1542 QString code; | |
1543 QTextStream tmpStream(&code); | |
1544 snip.formattedCode(tmpStream, INDENT); | |
1545 ArgumentMap map = snip.argumentMap; | |
1546 ArgumentMap::iterator it = map.begin(); | |
1547 for (;it!=map.end();++it) { | |
1548 int pos = it.key() - 1; | |
1549 QString meta_name = it.value(); | |
1550 | |
1551 if (pos >= 0 && pos < java_function->arguments().count()) { | |
1552 code = code.replace(meta_name, java_function->arguments().at(pos)->indexedName()); | |
1553 } else { | |
1554 QString debug = QString("argument map specifies invalid argument index %1" | |
1555 "for function '%2'") | |
1556 .arg(pos + 1).arg(java_function->name()); | |
1557 ReportHandler::warning(debug); | |
1558 } | |
1559 | |
1560 } | |
1561 s << code; | |
1562 if (position == CodeSnip::Beginning) | |
1563 s << endl; | |
1564 } | |
1565 } | |
1566 } | |
1567 | |
1568 static QString function_call_for_ownership(TypeSystem::Ownership owner, const QString &var_name) | |
1569 { | |
1570 if (owner == TypeSystem::CppOwnership) { | |
1571 return "setCppOwnership(__jni_env, " + var_name + ")"; | |
1572 } else if (owner == TypeSystem::TargetLangOwnership) { | |
1573 return "setJavaOwnership(__jni_env, " + var_name + ")"; | |
1574 } else if (owner == TypeSystem::DefaultOwnership) { | |
1575 return "setDefaultOwnership(__jni_env, " + var_name + ")"; | |
1576 } else { | |
1577 Q_ASSERT(false); | |
1578 return "bogus()"; | |
1579 } | |
1580 } | |
1581 | |
1582 void CppImplGenerator::writeOwnership(QTextStream &s, | |
1583 const AbstractMetaFunction *java_function, | |
1584 const QString &var_name, | |
1585 int var_index, | |
1586 const AbstractMetaClass *implementor) | |
1587 { | |
1588 TypeSystem::Ownership owner = TypeSystem::InvalidOwnership; | |
1589 const AbstractMetaClass *cls = implementor; | |
1590 while (cls != 0 && owner == TypeSystem::InvalidOwnership) { | |
1591 owner = java_function->ownership(cls, TypeSystem::ShellCode, var_index); | |
1592 cls = cls->baseClass(); | |
1593 } | |
1594 | |
1595 if (owner == TypeSystem::InvalidOwnership) | |
1596 return; | |
1597 | |
1598 if (var_index != -1) { | |
1599 s << INDENT << "if (" << var_name << " != 0) {" << endl; | |
1600 { | |
1601 Indentation indent(INDENT); | |
1602 s << INDENT << "QtJambiLink *__link = QtJambiLink::findLink(__jni_env, " | |
1603 << var_name << ");" << endl | |
1604 << INDENT << "Q_ASSERT(__link != 0);" << endl; | |
1605 | |
1606 s << INDENT << "__link->" << function_call_for_ownership(owner, var_name) << ";" << endl; | |
1607 } | |
1608 s << INDENT << "}" << endl; | |
1609 } else { | |
1610 s << INDENT << "if (m_link) {" << endl; | |
1611 { | |
1612 Indentation indent(INDENT); | |
1613 s << INDENT << "m_link->" << function_call_for_ownership(owner, "m_link->javaObject(__jni_env)") << ";" << endl; | |
1614 } | |
1615 s << INDENT << "}" << endl; | |
1616 } | |
1617 | |
1618 } | |
1619 | |
1620 void CppImplGenerator::writeShellFunction(QTextStream &s, const AbstractMetaFunction *java_function, | |
1621 const AbstractMetaClass *implementor, int id) | |
1622 { | |
1623 writeFunctionSignature(s, java_function, implementor, QString(), OriginalName); | |
1624 | |
1625 s << endl | |
1626 << "{" << endl; | |
1627 | |
1628 Indentation indent(INDENT); | |
1629 | |
1630 QString java_function_signature = java_function->signature(); | |
1631 /* s << INDENT << "QTJAMBI_DEBUG_TRACE(\"(shell) entering: " << implementor->name() << "::" | |
1632 << java_function_signature << "\");" << endl; | |
1633 */ | |
1634 writeCodeInjections(s, java_function, implementor, CodeSnip::Beginning, TypeSystem::ShellCode); | |
1635 | |
1636 // s << " printf(\"%s : %s\\n\", \"" << java_function->enclosingClass()->name() << "\"" | |
1637 // << ", \"" << java_function->name() << "\");" << endl; | |
1638 | |
1639 if (!java_function->isFinalInCpp() || java_function->isVirtualSlot()) { | |
1640 s << INDENT << "jmethodID method_id = m_vtable->method(" << id << ");" << endl; | |
1641 s << INDENT << "if (method_id) {" << endl; | |
1642 | |
1643 { | |
1644 Indentation indent(INDENT); | |
1645 s << INDENT << "JNIEnv *__jni_env = qtjambi_current_environment();" << endl; | |
1646 | |
1647 // This nasty case comes up when we're shutting down while receiving virtual | |
1648 // calls.. With these checks we safly abort... | |
1649 s << INDENT << "if (!__jni_env) {" << endl | |
1650 << " "; | |
1651 writeBaseClassFunctionCall(s, java_function, implementor); | |
1652 if (!java_function->type()) { | |
1653 s << INDENT << " return;" << endl; | |
1654 } | |
1655 s << INDENT << "}" << endl; | |
1656 | |
1657 // otherwise, continue with the function call... | |
1658 s << INDENT << "__jni_env->PushLocalFrame(100);" << endl; | |
1659 | |
1660 AbstractMetaArgumentList arguments = java_function->arguments(); | |
1661 AbstractMetaArgumentList argumentsToReset; | |
1662 foreach (AbstractMetaArgument *argument, arguments) { | |
1663 if (!java_function->argumentRemoved(argument->argumentIndex()+1)) { | |
1664 if (!argument->type()->isPrimitive() | |
1665 || !java_function->conversionRule(TypeSystem::NativeCode, argument->argumentIndex()+1).isEmpty()) { | |
1666 writeQtToJava(s, | |
1667 argument->type(), | |
1668 argument->indexedName(), | |
1669 "__java_" + argument->indexedName(), | |
1670 java_function, | |
1671 argument->argumentIndex() + 1); | |
1672 } | |
1673 | |
1674 if (java_function->resetObjectAfterUse(argument->argumentIndex()+1)) | |
1675 argumentsToReset.append(argument); | |
1676 } | |
1677 } | |
1678 | |
1679 for (int i=0; i<arguments.size(); ++i) | |
1680 writeOwnership(s, java_function, "__java_" + arguments.at(i)->indexedName(), i+1, implementor); | |
1681 | |
1682 | |
1683 AbstractMetaType *function_type = java_function->type(); | |
1684 QString new_return_type = java_function->typeReplaced(0); | |
1685 bool has_function_type = ((function_type != 0 | |
1686 || !new_return_type.isEmpty()) | |
1687 && new_return_type != "void"); | |
1688 | |
1689 s << INDENT; | |
1690 if (has_function_type) { | |
1691 if (new_return_type.isEmpty()) { | |
1692 s << translateType(function_type); | |
1693 } else { | |
1694 s << jniName(new_return_type); | |
1695 } | |
1696 s << " " << "__d_return_value = "; | |
1697 } | |
1698 | |
1699 s << "__jni_env->"; | |
1700 if (new_return_type.isEmpty()) { | |
1701 s << callXxxMethod(java_function->type()); | |
1702 } else if (!has_function_type) { | |
1703 s << "CallVoidMethod"; | |
1704 } else { | |
1705 s << callXxxMethod(new_return_type); | |
1706 } | |
1707 | |
1708 s << "(m_link->javaObject(__jni_env), method_id"; | |
1709 if (arguments.size() > 0) | |
1710 s << ", "; | |
1711 writeFunctionCallArguments(s, java_function, "__java_", Option(NoCasts | SkipRemovedArguments)); | |
1712 s << ");" << endl | |
1713 << INDENT << "qtjambi_exception_check(__jni_env);" << endl; | |
1714 | |
1715 if (has_function_type) { | |
1716 writeJavaToQt(s, function_type, "__qt_return_value", "__d_return_value", | |
1717 java_function, 0, GlobalRefJObject); | |
1718 | |
1719 if (java_function->nullPointersDisabled()) { | |
1720 s << INDENT << "if (__d_return_value == 0) {" << endl; | |
1721 { | |
1722 Indentation indent(INDENT); | |
1723 s << INDENT << "fprintf(stderr, \"QtJambi: Unexpected null pointer returned from override of '" << java_function->name() << "' in class '%s'\\n\"," << endl | |
1724 << INDENT << " qPrintable(qtjambi_object_class_name(__jni_env, m_link->javaObject(__jni_env))));" << endl; | |
1725 s << INDENT << "__qt_return_value = "; | |
1726 QString defaultValue = java_function->nullPointerDefaultValue(); | |
1727 if (!defaultValue.isEmpty()) | |
1728 s << defaultValue << ";"; | |
1729 else | |
1730 writeBaseClassFunctionCall(s, java_function, implementor, NoReturnStatement); | |
1731 s << endl; | |
1732 } | |
1733 | |
1734 s << INDENT << "}" << endl; | |
1735 } | |
1736 } else if (!java_function->conversionRule(TypeSystem::ShellCode, 0).isEmpty()) { | |
1737 writeConversionRule(s, TypeSystem::ShellCode, java_function, 0, "<invalid>", "<invalid>"); | |
1738 } | |
1739 | |
1740 writeOwnership(s, java_function, "this", -1, implementor); | |
1741 writeOwnership(s, java_function, "__d_return_value", 0, implementor); | |
1742 | |
1743 foreach (AbstractMetaArgument *argumentToReset, argumentsToReset) { | |
1744 | |
1745 QString argumentName = "__java_" + argumentToReset->indexedName(); | |
1746 | |
1747 s << INDENT; | |
1748 if (argumentToReset->type()->isContainer()) | |
1749 s << "qtjambi_invalidate_collection("; | |
1750 else | |
1751 s << "qtjambi_invalidate_object("; | |
1752 | |
1753 s << "__jni_env, " << argumentName << ");" << endl; | |
1754 } | |
1755 | |
1756 s << INDENT << "__jni_env->PopLocalFrame(0);" << endl; | |
1757 | |
1758 s << INDENT << "QTJAMBI_DEBUG_TRACE(\"(shell) -> leaving: " << implementor->name() | |
1759 << "::" << java_function_signature << "\");" << endl; | |
1760 | |
1761 if (function_type) | |
1762 s << INDENT << "return __qt_return_value;" << endl; | |
1763 | |
1764 } | |
1765 | |
1766 s << INDENT << "} else {" << endl; | |
1767 | |
1768 { | |
1769 Indentation indent(INDENT); | |
1770 s << INDENT << "QTJAMBI_DEBUG_TRACE(\"(shell) -> super() and leaving: " | |
1771 << implementor->name() << "::" << java_function_signature << "\");" << endl; | |
1772 writeBaseClassFunctionCall(s, java_function, implementor); | |
1773 } | |
1774 | |
1775 | |
1776 s << INDENT << "}" << endl; | |
1777 | |
1778 writeCodeInjections(s, java_function, implementor, CodeSnip::End, TypeSystem::ShellCode); | |
1779 | |
1780 // A little trick to close open painters on a widget | |
1781 if (java_function->name() == "paintEvent") { | |
1782 s << INDENT << "JNIEnv *env = qtjambi_current_environment();" << endl | |
1783 << INDENT << "qtjambi_end_paint(env, m_link->javaObject(env));" << endl; | |
1784 } | |
1785 | |
1786 } else { | |
1787 if(java_function->isRemovedFrom(implementor, TypeSystem::TargetLangCode)){ | |
1788 // Avoid compiler warnings for unused parameters | |
1789 AbstractMetaArgumentList arguments = java_function->arguments(); | |
1790 | |
1791 foreach (const AbstractMetaArgument *argument, arguments) { | |
1792 s << INDENT << "Q_UNUSED(" << argument->indexedName() << ")" << endl; | |
1793 } | |
1794 } | |
1795 writeBaseClassFunctionCall(s, java_function, implementor); | |
1796 writeCodeInjections(s, java_function, implementor, CodeSnip::End, TypeSystem::ShellCode); | |
1797 } | |
1798 | |
1799 s << "}" << endl << endl; | |
1800 | |
1801 } | |
1802 | |
1803 // ### kill implementor | |
1804 | |
1805 void CppImplGenerator::writePublicFunctionOverride(QTextStream &s, | |
1806 const AbstractMetaFunction *java_function, | |
1807 const AbstractMetaClass *implementor) | |
1808 { | |
1809 Q_ASSERT(java_function->originalAttributes() | |
1810 & (AbstractMetaAttributes::Protected | |
1811 | AbstractMetaAttributes::Final)); | |
1812 | |
1813 // The write a public override version of this function to be used by native functions | |
1814 writeFunctionSignature(s, java_function, implementor, "__public_", | |
1815 Option(EnumAsInts | UnderscoreSpaces | |
1816 | (java_function->isAbstract() ? SkipName : NoOption))); | |
1817 s << endl | |
1818 << "{" << endl; | |
1819 Indentation indent(INDENT); | |
1820 writeBaseClassFunctionCall(s, java_function, implementor); | |
1821 s << "}" << endl << endl; | |
1822 } | |
1823 | |
253 | 1824 void CppImplGenerator::writeQtdEntityFunction(QTextStream &s, const AbstractMetaClass *java_class) |
1825 { | |
1826 s << "extern \"C\" DLL_PUBLIC void *__" << java_class->name() << "_entity(void *q_ptr)" << endl; | |
1827 s << "{" << endl; | |
1828 { | |
1829 Indentation indent(INDENT); | |
1830 s << INDENT << "QtD_Entity* a = dynamic_cast<QtD_Entity*>((" << java_class->qualifiedCppName() << "*)q_ptr);" << endl | |
1831 << INDENT << "if (a != NULL)" << endl | |
1832 << INDENT << " return a->dId;" << endl | |
1833 << INDENT << "else" << endl | |
1834 << INDENT << " return NULL;" << endl; | |
1835 } | |
1836 s << "}" << endl << endl; | |
1837 } | |
1 | 1838 |
1839 void CppImplGenerator::writeVirtualFunctionOverride(QTextStream &s, | |
1840 const AbstractMetaFunction *java_function, | |
1841 const AbstractMetaClass *implementor) | |
1842 { | |
1843 Q_ASSERT(!java_function->isFinalInCpp()); | |
1844 | |
1845 Option options = Option(EnumAsInts | UnderscoreSpaces); | |
1846 | |
1847 // The write a public override version of this function to be used by native functions | |
1848 writeFunctionSignature(s, java_function, implementor, "__override_", | |
1849 options, | |
21 | 1850 QString(), // the class prefix |
1851 QStringList() << "bool static_call"); | |
1 | 1852 s << endl |
1853 << "{" << endl; | |
1854 Indentation indent(INDENT); | |
21 | 1855 s << INDENT << "if (static_call) {" << endl; |
1 | 1856 { |
21 | 1857 Indentation indent(INDENT); |
1 | 1858 writeBaseClassFunctionCall(s, java_function, implementor); |
21 | 1859 } |
1 | 1860 s << INDENT << "} else {" << endl; |
1861 { | |
1862 Indentation indent(INDENT); | |
1863 writeBaseClassFunctionCall(s, java_function, implementor, VirtualCall); | |
1864 } | |
1865 | |
21 | 1866 s << INDENT << "}" << endl; |
1 | 1867 s << "}" << endl << endl; |
1868 } | |
1869 | |
1870 | |
1871 void CppImplGenerator::writeBaseClassFunctionCall(QTextStream &s, | |
1872 const AbstractMetaFunction *java_function, | |
1873 const AbstractMetaClass *, | |
1874 Option options) | |
1875 { | |
1876 bool static_call = !(options & VirtualCall); | |
1877 if ((options & NoReturnStatement) == 0) | |
1878 s << INDENT; | |
1879 if (java_function->isAbstract() && static_call) { | |
1880 s << default_return_statement_qt(java_function->type(), options) << ";" << endl; | |
1881 } else { | |
1882 if (java_function->type() && (options & NoReturnStatement) == 0) | |
1883 s << "return "; | |
1884 if (static_call) { | |
1885 const AbstractMetaClass *implementor = java_function->implementingClass(); | |
1886 if (java_function->isInterfaceFunction()) | |
1887 implementor = java_function->interfaceClass()->primaryInterfaceImplementor(); | |
1888 s << implementor->qualifiedCppName() << "::"; | |
1889 } | |
1890 s << java_function->originalName() << "("; | |
1891 writeFunctionCallArguments(s, java_function, QString(), Option(options | ForceEnumCast)); | |
1892 s << ");" << endl; | |
1893 } | |
1894 } | |
1895 | |
1896 | |
1897 void CppImplGenerator::writeFunctionName(QTextStream &s, | |
1898 const AbstractMetaFunction *java_function, | |
1899 const AbstractMetaClass *java_class, | |
1900 uint options) | |
1901 { | |
1902 const AbstractMetaClass *cls = java_class ? java_class : java_function->ownerClass(); | |
1903 AbstractMetaArgumentList arguments = java_function->arguments(); | |
1904 | |
1905 // Function signature | |
1906 QString return_type = jniReturnName(java_function, options); | |
1907 | |
1908 QString function_name; | |
1909 | |
1910 bool callThrough = java_function->needsCallThrough(); | |
1911 /* qtd if (!callThrough) | |
1912 function_name = java_function->name(); | |
1913 else */ | |
1914 function_name = java_function->marshalledName(); | |
1915 | |
1916 QString args = "__"; | |
1917 | |
1918 if (callThrough && !java_function->isStatic() && !java_function->isConstructor()) | |
1919 args += "J"; | |
1920 | |
1921 if (!arguments.isEmpty()) { | |
1922 foreach (const AbstractMetaArgument *argument, arguments) { | |
1923 if (!java_function->argumentRemoved(argument->argumentIndex() + 1)) { | |
1924 if (!argument->type()->hasNativeId()) { | |
1925 QString modified_type = java_function->typeReplaced(argument->argumentIndex()+1); | |
1926 if (modified_type.isEmpty()) | |
1927 args += jni_signature(argument->type(), Underscores); | |
1928 else | |
1929 args += jni_signature(modified_type, Underscores); | |
1930 } else { | |
1931 args += "J"; | |
1932 } | |
1933 } | |
1934 } | |
1935 } | |
1936 | |
1937 s << jni_function_signature(cls->package(), cls->name(), function_name, | |
1938 return_type, args, options); | |
1939 | |
1940 } | |
1941 | |
1942 void CppImplGenerator::writeFinalFunctionArguments(QTextStream &s, const AbstractMetaFunction *java_function, bool d_export) | |
1943 { | |
1944 bool callThrough = java_function->needsCallThrough(); | |
1945 s << "("; | |
1946 /* qtd | |
1947 << "JNIEnv *__jni_env," << endl; | |
1948 if (!java_function->isConstructor()) { | |
1949 if (java_function->isStatic()) | |
1950 s << " jclass"; | |
1951 else | |
1952 s << " jobject"; | |
1953 } else | |
1954 s << " jobject " << java_object_name; | |
1955 */ | |
1956 uint nativeArgCount = 0; | |
1957 const AbstractMetaClass *cls = java_function->ownerClass(); | |
1958 if (java_function->isConstructor() && | |
1959 ( cls->hasVirtualFunctions() | |
1960 || cls->typeEntry()->isObject() ) ) | |
1961 { | |
1962 s << "void *d_ptr"; | |
1963 nativeArgCount++; | |
1964 } | |
1965 | |
1966 // passing pointer to C++ object | |
1967 bool hasNativeId = (callThrough && !java_function->isStatic() && !java_function->isConstructor()); | |
1968 if (hasNativeId) { | |
1969 if (nativeArgCount > 0) | |
1970 s << "," << endl << " "; | |
1971 /* qtd << "," << endl */ s << "void* __this_nativeId"; | |
1972 nativeArgCount++; | |
1973 } | |
1974 | |
1975 AbstractMetaType *f_type = java_function->type(); | |
1976 | |
1977 // return values as strings, arrays or QModelIndex'es we return as arguments | |
1978 bool return_arg = false; | |
1979 if (f_type) { | |
1980 if (f_type->isTargetLangString() || | |
1981 f_type->isContainer() || | |
81 | 1982 f_type->name() == "QModelIndex" || |
1983 f_type->typeEntry()->isStructInD()) | |
1 | 1984 return_arg = true; |
1985 | |
1986 if (return_arg && nativeArgCount > 0) | |
1987 s << "," << endl << " "; | |
1988 | |
1989 if (f_type->isTargetLangString() || f_type->isContainer()) | |
1990 s << "void*"; | |
1991 else if (f_type->name() == "QModelIndex") | |
1992 s << "QModelIndexAccessor*"; | |
81 | 1993 else if (f_type->typeEntry()->isStructInD()) |
1994 s << f_type->typeEntry()->qualifiedCppName() << " *"; | |
1 | 1995 |
1996 if(return_arg) { | |
1997 s << " __d_return_value"; | |
1998 nativeArgCount++; | |
1999 } | |
2000 } | |
2001 | |
2002 // the function arguments | |
2003 AbstractMetaArgumentList arguments = java_function->arguments(); | |
2004 foreach (const AbstractMetaArgument *argument, arguments) { | |
2005 if (!java_function->argumentRemoved(argument->argumentIndex() + 1)) { | |
2006 AbstractMetaType *d_type = argument->type(); | |
2007 const TypeEntry *te = d_type->typeEntry(); | |
2008 | |
2009 QString arg_name = argument->indexedName(); | |
2010 | |
2011 if (nativeArgCount > 0) | |
2012 s << "," << endl << " "; | |
81 | 2013 |
2014 // if QString argument we have to pass DArray | |
35 | 2015 if ((te && te->qualifiedCppName() == "QString") || d_type->isTargetLangString()) { |
2016 if (d_export) | |
2017 s << "string " << arg_name; | |
2018 else | |
2019 s << "DArray " << arg_name; | |
2020 } else if (d_type->isContainer()) { | |
1 | 2021 const ContainerTypeEntry *cte = |
2022 static_cast<const ContainerTypeEntry *>(te); | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
2023 if(cte->isQList()) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
2024 s << "void* " << arg_name; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
2025 else if(isLinearContainer(cte)) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
2026 s << "DArray* " << arg_name; |
1 | 2027 } else { |
2028 if (!d_type->hasNativeId()) { | |
2029 if(d_type->isVariant()) { | |
2030 if (d_export) s << "void*"; | |
2031 else s << "QVariant*"; | |
2032 } else | |
2033 s << translateType(argument->type(), EnumAsInts, d_export); | |
2034 } | |
188 | 2035 else if (d_type->name() == "QModelIndex") { |
2036 if(d_export && dVersion == 2 && d_type->isConstant()) | |
2037 s << "const(QModelIndexAccessor)"; | |
2038 else | |
2039 s << "QModelIndexAccessor"; | |
2040 } else if (te->isStructInD()) | |
1 | 2041 s << te->qualifiedCppName(); |
2042 else | |
2043 s << "void*"; | |
2044 | |
2045 s << " " << arg_name; | |
2046 } | |
2047 nativeArgCount++; | |
2048 } | |
2049 } | |
2050 s << ")"; | |
2051 } | |
2052 | |
2053 | |
2054 /*! | |
2055 Generates type conversion from Java -> Qt for all the arguments | |
2056 that are to be to be passed to the function | |
2057 */ | |
2058 void CppImplGenerator::writeFinalFunctionSetup(QTextStream &s, const AbstractMetaFunction *java_function, | |
2059 const QString &qt_object_name, | |
2060 const AbstractMetaClass *cls) | |
2061 { | |
2062 | |
2063 // Translate each of the function arguments into qt types | |
2064 AbstractMetaArgumentList arguments = java_function->arguments(); | |
2065 foreach (const AbstractMetaArgument *argument, arguments) { | |
2066 if (!argument->type()->isPrimitive() | |
2067 || !java_function->conversionRule(TypeSystem::NativeCode, argument->argumentIndex() + 1).isEmpty()) { | |
2068 writeJavaToQt(s, | |
2069 argument->type(), | |
2070 "__qt_" + argument->indexedName(), | |
2071 argument->indexedName(), | |
2072 java_function, | |
2073 argument->argumentIndex() + 1, | |
2074 Option(UseNativeIds | EnumAsInts)); | |
2075 } | |
2076 } | |
2077 | |
2078 // Extract the qt equivalent to the this pointer and name it "qt_object_name" | |
2079 if (!java_function->isStatic() && !java_function->isConstructor()) { | |
2080 // qtd2 QString className = java_function->isFinalOverload() ? cls->name() : shellClassName(cls); | |
2081 QString className = java_function->isFinalOverload() ? cls->name() : shellClassName(cls); | |
2082 s << INDENT | |
2083 << className << " *" << qt_object_name | |
2084 << " = (" << className << " *) __this_nativeId;" | |
2085 << endl; | |
2086 // << INDENT << "QTJAMBI_EXCEPTION_CHECK(__jni_env);" << endl | |
2087 // qtd << INDENT << "Q_ASSERT(" << qt_object_name << ");" << endl; | |
2088 } | |
2089 } | |
2090 | |
2091 void CppImplGenerator::writeFinalFunction(QTextStream &s, const AbstractMetaFunction *java_function, | |
2092 const AbstractMetaClass *java_class) | |
2093 { | |
2094 Q_ASSERT(java_class); | |
2095 | |
2096 if (java_function->isModifiedRemoved(TypeSystem::NativeCode)) | |
2097 return; | |
2098 | |
2099 const AbstractMetaClass *cls = java_class ? java_class : java_function->ownerClass(); | |
2100 | |
2101 QString java_function_signature = cls->name() + "::" + java_function->signature(); | |
2102 | |
2103 s << "// " << java_function_signature << endl; | |
2104 | |
2105 const AbstractMetaType *function_type = java_function->type(); | |
2106 QString new_return_type = java_function->typeReplaced(0); | |
2107 bool has_function_type = new_return_type != "void" | |
2108 && (!new_return_type.isEmpty() || function_type != 0) | |
2109 && java_function->argumentReplaced(0).isEmpty(); | |
2110 | |
2111 const QString qt_object_name = java_function->isStatic() ? shellClassName(cls) : "__qt_this"; | |
2112 const QString java_object_name = java_function->isStatic() ? "__jni_class" : "__jni_object"; | |
2113 | |
2114 // we are not wrapping some functions depending on arguments because API is not yet full | |
2115 if (notWrappedYet(java_function)) | |
2116 return; | |
2117 | |
2118 // function signature... | |
2119 bool callThrough = java_function->needsCallThrough(); | |
2120 uint options = m_native_jump_table ? ReturnType | ExternC : StandardJNISignature; | |
2121 writeFunctionName(s, java_function, cls, options); | |
2122 s << endl; | |
2123 writeFinalFunctionArguments(s, java_function); | |
2124 s << endl << "{" << endl; | |
2125 Indentation indent(INDENT); | |
2126 | |
2127 // qtd2 s << INDENT << "QTJAMBI_DEBUG_TRACE(\"(native) entering: " << java_function_signature << "\");" << endl; | |
2128 bool hasNativeId = (callThrough && !java_function->isStatic() && !java_function->isConstructor()); | |
2129 /* if (hasNativeId) | |
2130 s << INDENT << "Q_UNUSED(__this_nativeId)" << endl; | |
2131 // Avoid compiler warnings when the variables are unused | |
2132 { | |
2133 s << INDENT << "Q_UNUSED(__jni_env)" << endl; | |
2134 | |
2135 if (java_function->isConstructor()) | |
2136 s << INDENT << "Q_UNUSED(" << java_object_name << ")" << endl; | |
2137 | |
2138 bool hasNativeId = (callThrough && !java_function->isStatic() && !java_function->isConstructor()); | |
2139 if (hasNativeId) | |
2140 s << INDENT << "Q_UNUSED(__this_nativeId)" << endl; | |
2141 } | |
2142 */ | |
2143 | |
2144 if (cls->isFinal() && (!java_function->isAbstract() || !java_function->isFinalInTargetLang()) && !java_function->wasPublic()) { | |
2145 QString debug = QString("protected function '%1' in final class '%2'") | |
2146 .arg(java_function->signature()).arg(java_class->name()); | |
2147 ReportHandler::warning(debug); | |
2148 // Avoid compiler warnings for unused parameters | |
2149 AbstractMetaArgumentList arguments = java_function->arguments(); | |
2150 | |
2151 foreach (const AbstractMetaArgument *argument, arguments) { | |
2152 s << INDENT << "Q_UNUSED(" << argument->indexedName() << ")" << endl; | |
2153 } | |
2154 s << INDENT << default_return_statement_qt(java_function->type()) << ""; | |
2155 } else { | |
2156 writeFinalFunctionSetup(s, java_function, qt_object_name, cls); | |
2157 | |
2158 writeCodeInjections(s, java_function, java_function->implementingClass(), CodeSnip::Beginning, TypeSystem::NativeCode); | |
2159 | |
2160 if (java_function->isConstructor()) { | |
2161 writeFinalConstructor(s, java_function, qt_object_name, java_object_name); | |
2162 } else { | |
2163 | |
2164 QString function_prefix = ""; | |
2165 QStringList extra_param; | |
2166 Option option = NoOption; | |
2167 | |
2168 bool hasShell = cls->generateShellClass(); | |
2169 | |
2170 if (java_function->isFinalOverload()) { | |
2171 // no prefix | |
2172 } else if (java_function->isFinalInCpp() && !java_function->wasPublic() && hasShell) { | |
2173 function_prefix = "__public_"; | |
2174 } else if (!java_function->isFinalInCpp() && !java_function->isStatic() && hasShell) { | |
2175 function_prefix = "__override_"; | |
21 | 2176 extra_param.append("__do_static_call"); |
1 | 2177 s << INDENT |
253 | 2178 << "bool __do_static_call = __this_nativeId ? "; |
2179 if (java_class->isQObject()) | |
2180 s << "QtD_QObjectEntity::getQObjectEntity((QObject*)__this_nativeId) : false;" << endl; | |
2181 else | |
2182 s << "__" << java_class->name() << "_entity(__this_nativeId) : false;" << endl; | |
21 | 2183 } else { |
1 | 2184 option = OriginalName; |
2185 } | |
2186 | |
2187 // Call the Qt function on the java object | |
2188 s << " "; | |
2189 if (has_function_type) { | |
2190 const QString qt_return_value = "__qt_return_value"; | |
2191 const QString java_return_value = "__d_return_value"; | |
2192 if (function_type) { | |
2193 writeTypeInfo(s, function_type, EnumAsInts); | |
2194 s << " " << qt_return_value | |
2195 << " = "; | |
2196 } | |
2197 | |
2198 writeFunctionCall(s, qt_object_name, java_function, function_prefix, option, | |
2199 extra_param); | |
2200 s << endl; | |
2201 | |
104 | 2202 writeRefArguments(s, java_function); |
2203 | |
1 | 2204 writeQtToJava(s, function_type, qt_return_value, java_return_value, |
2205 java_function, 0, EnumAsInts); | |
2206 | |
2207 // qtd s << INDENT << "QTJAMBI_DEBUG_TRACE(\"(native) -> leaving: " | |
2208 // << java_function_signature << "\");"; | |
2209 | |
2210 if (function_type && function_type->name() != "QModelIndex") { | |
2211 if(function_type->typeEntry()->isStructInD()) | |
81 | 2212 ; //s << endl << INDENT << "return " << qt_return_value << ";"; |
1 | 2213 else if (!function_type->isTargetLangString() && !function_type->isContainer()) |
2214 s << endl << INDENT << "return " << java_return_value << ";"; | |
2215 } | |
2216 | |
2217 } else { | |
2218 writeFunctionCall(s, qt_object_name, java_function, function_prefix, option, | |
2219 extra_param); | |
104 | 2220 writeRefArguments(s, java_function); |
1 | 2221 } |
2222 } | |
2223 } | |
2224 if(!java_function->argumentReplaced(0).isEmpty()) { | |
2225 s << INDENT << "return 0;" << endl; | |
2226 } | |
2227 | |
2228 s << endl << "}"; | |
2229 s << endl << endl; | |
2230 } | |
2231 | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2232 void CppImplGenerator::writeRefArguments(QTextStream &s, const AbstractMetaFunction *java_function) |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2233 { |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2234 AbstractMetaArgumentList arguments = java_function->arguments(); |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2235 foreach (const AbstractMetaArgument *argument, arguments) { |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2236 AbstractMetaType *d_type = argument->type(); |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2237 const TypeEntry *te = d_type->typeEntry(); |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2238 if ((te && d_type->isNativePointer() && te->name() == "QString")) |
253 | 2239 s << QString(" qtd_toUtf8(__qt_%1.utf16(), __qt_%1.size(), &%1);").arg(argument->indexedName()) << endl; |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2240 } |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2241 } |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2242 |
1 | 2243 void CppImplGenerator::writeAssignment(QTextStream &s, const QString &destName, const QString &srcName, |
2244 const AbstractMetaType *java_type) | |
2245 { | |
2246 if (java_type->isArray()) { | |
2247 for (int i=0; i<java_type->arrayElementCount(); ++i) { | |
2248 writeAssignment(s, destName + "[" + QString::number(i) + "]", | |
2249 srcName + "[" + QString::number(i) + "]", java_type->arrayElementType()); | |
2250 } | |
2251 } else { | |
2252 s << INDENT << destName << " = " << srcName << ";" << endl; | |
2253 } | |
2254 } | |
2255 | |
2256 void CppImplGenerator::writeFieldAccessors(QTextStream &s, const AbstractMetaField *java_field) | |
2257 { | |
2258 Q_ASSERT(java_field); | |
2259 Q_ASSERT(java_field->isPublic() || java_field->isProtected()); | |
2260 | |
2261 const AbstractMetaFunction *setter = java_field->setter(); | |
2262 const AbstractMetaFunction *getter = java_field->getter(); | |
2263 | |
2264 const AbstractMetaClass *cls = java_field->enclosingClass(); | |
2265 FieldModification mod = cls->typeEntry()->fieldModification(java_field->name()); | |
2266 | |
2267 if(notWrappedYet(getter)) | |
2268 return; | |
2269 | |
2270 if (mod.isReadable()) { | |
2271 // Getter | |
2272 if (getter->wasProtected()) { | |
2273 writeFunctionSignature(s, getter, getter->ownerClass()); | |
2274 s << endl | |
2275 << "{" << endl; | |
2276 { | |
2277 Indentation indent(INDENT); | |
2278 s << INDENT << "return " << java_field->name() << ";" << endl; | |
2279 } | |
2280 s << "}" << endl << endl; | |
2281 } | |
2282 | |
2283 | |
2284 writeFunctionName(s, getter, getter->ownerClass()); | |
2285 s << endl; | |
2286 writeFinalFunctionArguments(s, getter); | |
2287 s << "{" << endl; | |
2288 { | |
2289 Indentation indent(INDENT); | |
2290 | |
2291 | |
2292 writeFinalFunctionSetup(s, getter, "__qt_object", getter->ownerClass()); | |
2293 | |
2294 const QString java_return_value = "__d_return_value"; | |
2295 QString qt_return_value; | |
2296 if (setter->isStatic()) | |
2297 qt_return_value = shellClassName(setter->ownerClass()) + "::"; | |
2298 else | |
2299 qt_return_value = "__qt_object->"; | |
2300 | |
2301 | |
2302 // To avoid "taking address of tmp" | |
2303 s << INDENT; | |
2304 writeTypeInfo(s, getter->type(), Option(ArrayAsPointer)); | |
2305 QString tmp_name = "__tmp_" + getter->name(); | |
2306 s << tmp_name << " = "; | |
2307 | |
2308 if (getter->wasPublic()) | |
2309 qt_return_value += java_field->name(); | |
2310 else | |
2311 qt_return_value += getter->name() + "_getter()"; | |
2312 s << qt_return_value << ";" << endl; | |
2313 | |
2314 writeQtToJava(s, getter->type(), tmp_name, java_return_value, 0, -1, EnumAsInts); | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2315 if (getter->type()->isTargetLangString() || getter->type()->name() == "QModelIndex") |
1 | 2316 ; |
2317 else if(getter->type()->typeEntry()->isStructInD()) | |
81 | 2318 ; //s << INDENT << "return " << tmp_name << ";" << endl; |
1 | 2319 else |
2320 s << INDENT << "return " << java_return_value << ";" << endl; | |
2321 } | |
2322 s << "}" << endl << endl; | |
2323 } | |
2324 | |
2325 if(notWrappedYet(setter)) | |
2326 return; | |
2327 | |
2328 // Setter | |
2329 if (mod.isWritable() && !java_field->type()->isConstant()) { | |
2330 // Write public override for protected fields | |
2331 if (setter->wasProtected()) { | |
2332 writeFunctionSignature(s, setter, setter->ownerClass()); | |
2333 s << endl | |
2334 << "{" << endl; | |
2335 { | |
2336 Indentation indent(INDENT); | |
2337 | |
2338 Q_ASSERT(setter->arguments().count() > 0); | |
2339 const AbstractMetaArgument *argument = setter->arguments().at(0); | |
2340 | |
2341 QString thisRef = java_field->isStatic() | |
2342 ? setter->ownerClass()->qualifiedCppName() + QString("::") | |
2343 : QString("this->"); | |
2344 writeAssignment(s, thisRef + java_field->name(), argument->indexedName(), argument->type()); | |
2345 } | |
2346 s << "}" << endl << endl; | |
2347 } | |
2348 | |
2349 writeFunctionName(s, setter, setter->ownerClass()); | |
2350 s << endl; | |
2351 writeFinalFunctionArguments(s, setter); | |
2352 s << "{" << endl; | |
2353 | |
2354 { | |
2355 Indentation indent(INDENT); | |
2356 | |
2357 writeFinalFunctionSetup(s, setter, "__qt_object", setter->ownerClass()); | |
2358 | |
2359 Q_ASSERT(setter->arguments().count() == 1); | |
2360 const AbstractMetaArgument *argument = setter->arguments().at(0); | |
2361 | |
2362 QString dest; | |
2363 if (setter->isStatic()) | |
2364 dest = shellClassName(setter->ownerClass()) + "::"; | |
2365 else | |
2366 dest = "__qt_object->"; | |
2367 | |
2368 QString src; | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2369 if (!argument->type()->isPrimitive() && !argument->type()->typeEntry()->isStructInD()) { |
1 | 2370 src = "__qt_" + argument->indexedName(); |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2371 } else if (argument->type()->name() == "QModelIndex") { |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2372 src = "qtd_to_QModelIndex(" + argument->indexedName() + ")"; |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2373 } else |
1 | 2374 src = argument->indexedName(); |
2375 | |
2376 if (setter->wasPublic()) | |
2377 writeAssignment(s, dest + java_field->name(), src, argument->type()); | |
2378 else | |
2379 s << INDENT << dest << setter->name() << "_setter(" << src << ");" << endl; | |
2380 } | |
2381 s << "}" << endl << endl; | |
2382 } | |
2383 } | |
2384 | |
2385 void CppImplGenerator::writeFinalDestructor(QTextStream &s, const AbstractMetaClass *cls) | |
2386 { | |
2387 if (cls->hasConstructors()) { | |
2388 s << INDENT << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_destructor(void *ptr)" << endl | |
294 | 2389 << INDENT << "{" << endl |
2390 << INDENT << " delete (" << shellClassName(cls) << " *)ptr;" << endl | |
2391 << INDENT << "}" << endl << endl; | |
2392 | |
2393 s << INDENT << "extern \"C\" DLL_PUBLIC void qtd_" << cls->name() << "_call_destructor(" << shellClassName(cls) << " *ptr)" << endl | |
2394 << INDENT << "{" << endl | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
2395 << INDENT << " call_destructor(ptr);" << endl |
294 | 2396 << INDENT << "}" << endl << endl; |
1 | 2397 } |
2398 } | |
2399 | |
2400 void CppImplGenerator::writeFinalConstructor(QTextStream &s, | |
2401 const AbstractMetaFunction *java_function, | |
2402 const QString &qt_object_name, | |
293 | 2403 const QString &java_object_name, |
2404 const QString &place) | |
1 | 2405 { |
2406 const AbstractMetaClass *cls = java_function->ownerClass(); | |
2407 AbstractMetaArgumentList arguments = java_function->arguments(); | |
2408 QString className = cls->typeEntry()->qualifiedCppName(); | |
2409 | |
2410 bool hasShellClass = cls->generateShellClass(); | |
2411 | |
2412 s << INDENT << shellClassName(cls) << " *" << qt_object_name | |
293 | 2413 << " = new " << place << shellClassName(cls) |
1 | 2414 << "("; |
2415 writeFunctionCallArguments(s, java_function, "__qt_"); | |
2416 s << ");" << endl; | |
2417 s << INDENT << "return (void *) " << qt_object_name << ";" << endl; // qtd | |
2418 | |
2419 /* qtd s << INDENT << "QtJambiLink *__qt_java_link = "; | |
2420 if (cls->isQObject()) { | |
2421 s << "qtjambi_construct_qobject(__jni_env, " << java_object_name << ", " | |
2422 << qt_object_name << ")"; | |
2423 } else { | |
2424 s << "qtjambi_construct_object(__jni_env, " << java_object_name << ", " << qt_object_name; | |
2425 if (cls->typeEntry()->isValue()) | |
2426 s << ", \"" << className << "\")"; | |
2427 else // non-QObject, object type | |
2428 s << ", QMetaType::Void, QLatin1String(\"" << cls->fullName().replace(".", "/") << "\"), true)"; | |
2429 } | |
2430 s << ";" << endl | |
2431 << INDENT << "if (!__qt_java_link) {" << endl; | |
2432 { | |
2433 Indentation indent(INDENT); | |
2434 s << INDENT << "qWarning(\"object construction failed for type: " | |
2435 << className << "\");" << endl | |
2436 << INDENT << "return;" << endl; | |
2437 } | |
2438 s << INDENT << "}" << endl; | |
2439 | |
2440 | |
2441 if (cls->isQObject()) { | |
2442 // Make sure all qobjects created by Java are owned by java only if | |
2443 // parent object has not been set. | |
2444 // All other objects will default to split ownership. | |
2445 s << INDENT << "if(!__qt_this->QObject::parent()){" << endl; | |
2446 s << INDENT << " __qt_java_link->setJavaOwnership(__jni_env, " << java_object_name << ");" << endl; | |
2447 s << INDENT << "}" << endl; | |
2448 } else { | |
2449 // All non-qobjects created by Java are owned by java | |
2450 s << INDENT << "__qt_java_link->setJavaOwnership(__jni_env, " << java_object_name << ");" << endl; | |
2451 } | |
2452 | |
2453 if (hasCustomDestructor(cls)) { | |
2454 s << INDENT << "__qt_java_link->setDestructorFunction(qtjambi_destructor);" << endl; | |
2455 } | |
2456 | |
2457 if (cls->typeEntry()->typeFlags() & ComplexTypeEntry::DeleteInMainThread) | |
2458 s << INDENT << "__qt_java_link->setDeleteInMainThread(true);" << endl; | |
2459 | |
2460 if (!cls->hasVirtualFunctions() && !cls->hasInconsistentFunctions() && !cls->typeEntry()->isObject()) | |
2461 return; | |
2462 | |
2463 if (hasShellClass) { | |
2464 // Set up the link object | |
2465 s << INDENT << qt_object_name << "->m_link = __qt_java_link;" << endl; | |
2466 | |
2467 // Make sure the user data in the QObject has bindings to the qobject's meta object | |
2468 // (this has to be done after the link is set, so that the fake meta object | |
2469 // can access the java object, for which it gets a reference in the link) | |
2470 if (cls->isQObject()) | |
2471 s << INDENT << qt_object_name << "->m_link->setMetaObject(" << qt_object_name << "->metaObject());" << endl; | |
2472 | |
2473 s << INDENT << qt_object_name << "->m_link->setCreatedByJava(true);" << endl; | |
2474 | |
2475 | |
2476 | |
2477 AbstractMetaClassList interfaces = cls->interfaces(); | |
2478 if (interfaces.size() + (cls->baseClass() != 0 ? 1 : 0) > 1) { | |
2479 if (cls->baseClass() != 0) | |
2480 interfaces += cls->baseClass(); | |
2481 foreach (AbstractMetaClass *iface, interfaces) { | |
2482 AbstractMetaClass *impl = iface->isInterface() ? iface->primaryInterfaceImplementor() : iface; | |
2483 s << INDENT << qt_object_name << "->m_link->registerSubObject((" << impl->qualifiedCppName() << " *) " << qt_object_name << ");" << endl; | |
2484 } | |
2485 } | |
2486 } | |
2487 | |
2488 if (!cls->hasVirtualFunctions() && !cls->hasInconsistentFunctions()) | |
2489 return; | |
2490 | |
2491 // Set up the vtable | |
2492 s << INDENT; | |
2493 QString space(24, ' '); | |
2494 if (hasShellClass) | |
2495 s << qt_object_name << "->m_vtable = "; | |
2496 s << "qtjambi_setup_vtable(__jni_env, " << endl << space << "__jni_object, " << endl; | |
2497 | |
2498 if (cls->hasInconsistentFunctions()) { | |
2499 s << space << "qtjambi_inconsistent_count, " << endl | |
2500 << space << "qtjambi_inconsistent_names, " << endl | |
2501 << space << "qtjambi_inconsistent_signatures, " << endl; | |
2502 } else { | |
2503 s << space << "0, 0, 0, // no inconsistent functions" << endl; | |
2504 } | |
2505 | |
2506 if (cls->hasVirtualFunctions()) { | |
2507 s << space << "qtjambi_method_count, " << endl | |
2508 << space << "qtjambi_method_names, " << endl | |
2509 << space << "qtjambi_method_signatures" << endl; | |
2510 } else { | |
2511 s << space << "0, 0, 0 // no virtual functions" << endl; | |
2512 } | |
2513 | |
2514 s << space << ");" << endl; */ | |
2515 } | |
2516 | |
2517 void CppImplGenerator::writeSignalInitialization(QTextStream &s, const AbstractMetaClass *java_class) | |
2518 { | |
2519 if (!java_class->isQObject() | |
2520 || java_class->queryFunctions(AbstractMetaClass::Signals | AbstractMetaClass::Visible | AbstractMetaClass::NotRemovedFromTargetLang).size() == 0) { | |
2521 return ; | |
2522 } | |
2523 | |
2524 s << jni_function_signature(java_class->package(), java_class->name(), "__qt_signalInitialization", "jboolean") | |
2525 << endl << "(JNIEnv *__jni_env, jobject java_object, jlong ptr, jstring java_signal_name)" << endl | |
2526 << "{" << endl | |
2527 << " QtJambiLink *link = (QtJambiLink *) ptr;" << endl | |
2528 << " if (link == 0)" << endl | |
2529 << " return true;" << endl << endl | |
2530 << " QObject *qt_this = link->qobject();" << endl | |
2531 << " Q_ASSERT(qt_this);" << endl << endl | |
2532 << " QtJambi_SignalWrapper_" << java_class->name() << " *qt_wrapper = " | |
2533 << " (QtJambi_SignalWrapper_" << java_class->name() << " *) link->signalWrapper();" << endl | |
2534 << " if (qt_wrapper == 0) {" << endl | |
2535 << " qt_wrapper = new QtJambi_SignalWrapper_" << java_class->name() << ";" << endl | |
2536 << " link->setSignalWrapper(qt_wrapper);" << endl | |
2537 << " qt_wrapper->link = link;" << endl << endl | |
2538 << " qtjambi_resolve_signals(__jni_env," << endl | |
2539 << " java_object," << endl | |
2540 << " qt_wrapper->m_signals," << endl | |
2541 << " qtjambi_signal_count," << endl | |
2542 << " (char **) qtjambi_signal_names," << endl | |
2543 << " (int *) qtjambi_signal_argumentcounts);" << endl | |
2544 << " }" << endl | |
2545 << " QString signal_name = qtjambi_to_qstring(__jni_env, java_signal_name);" << endl | |
2546 << " return qtjambi_connect_cpp_to_java(__jni_env," << endl | |
2547 << " signal_name," << endl | |
2548 << " qt_this," << endl | |
2549 << " qt_wrapper," << endl | |
2550 << " QLatin1String(\"" << java_class->fullName() << "\")," << endl | |
2551 << " QLatin1String(\"" << signalWrapperPrefix() << "\"));" << endl | |
2552 << "}"; | |
2553 } | |
2554 | |
2555 QString CppImplGenerator::fromObject(const TypeEntry *entry, | |
2556 const QString &var_name) | |
2557 { | |
2558 QString returned; | |
2559 QString package = entry->javaPackage(); | |
2560 const ComplexTypeEntry *centry = entry->isComplex() | |
2561 ? static_cast<const ComplexTypeEntry *>(entry) | |
2562 : 0; | |
2563 | |
2564 if (centry == 0 || centry->polymorphicIdValue().isEmpty()) { | |
2565 /* qtd returned = "qtjambi_from_object(__jni_env, " + var_name + ", \"" | |
2566 + entry->lookupName() | |
2567 + "\", \"" + QString(package).replace(".", "/") + "/\", true);"; | |
2568 */ | |
2569 if(entry->isObject()) | |
2570 returned = var_name + ";"; | |
2571 else | |
2572 returned = "new " + entry->lookupName() + "(" + var_name +");"; | |
2573 } else { | |
2574 AbstractMetaClass *cls = classes().findClass(centry->qualifiedCppName()); | |
2575 if (!cls) { | |
2576 qFatal("CppImplGenerator::fromObject(): class '%s' could not be resolved...", | |
2577 qPrintable(centry->qualifiedCppName())); | |
2578 } | |
2579 | |
2580 while (cls != 0 && !cls->typeEntry()->isPolymorphicBase()) | |
2581 cls = cls->baseClass(); | |
2582 | |
2583 QString full_name; | |
2584 if (cls != 0) { | |
2585 full_name = cls->fullName(); | |
2586 } else { | |
2587 ReportHandler::warning(QString("class '%1' has polymorphic id but does not inherit a polymorphic class") | |
2588 .arg(centry->qualifiedCppName())); | |
2589 } | |
2590 /* qtd | |
2591 returned = "qtjambi_from_object(__jni_env, " + var_name + ", \"" | |
2592 + centry->lookupName() | |
2593 + "\", \"" + QString(package).replace(".", "/") + "/\"," | |
2594 + "\"" + jni_signature(full_name, Underscores) + "\", true); // fucking complex"; | |
2595 */ | |
2596 if(entry->isObject()) | |
2597 returned = var_name + "; // complex entry"; | |
2598 else | |
2599 returned = "new " + centry->lookupName() + "(" + var_name +"); // complex entry"; | |
2600 } | |
2601 | |
2602 return returned; | |
2603 } | |
2604 | |
2605 void CppImplGenerator::writeOriginalMetaObjectFunction(QTextStream &s, const AbstractMetaClass *java_class) | |
2606 { | |
2607 Q_ASSERT(java_class->isQObject()); | |
2608 | |
2609 s << jni_function_signature(java_class->package(), | |
2610 java_class->name(), | |
2611 "originalMetaObject", | |
2612 "jlong"); | |
2613 | |
2614 s << endl | |
2615 << "(JNIEnv *," << endl | |
2616 << " jclass)" << endl | |
2617 << "{" << endl; | |
2618 { | |
2619 Indentation indent(INDENT); | |
2620 s << INDENT << "return reinterpret_cast<jlong>(&" << java_class->qualifiedCppName() << "::staticMetaObject);" << endl; | |
2621 } | |
2622 s << "}" << endl << endl; | |
2623 } | |
2624 | |
2625 void CppImplGenerator::writeFromNativeFunction(QTextStream &s, const AbstractMetaClass *java_class) | |
2626 { | |
2627 s << jni_function_signature(java_class->package(), | |
2628 java_class->name(), | |
2629 "fromNativePointer", | |
2630 "jobject"); | |
2631 s << endl | |
2632 << "(JNIEnv *__jni_env," << endl | |
2633 << " jclass," << endl | |
2634 << " jobject nativePointer)" << endl | |
2635 << "{" << endl; | |
2636 { | |
2637 Indentation indent(INDENT); | |
2638 s << INDENT << "void *ptr = qtjambi_to_cpointer(__jni_env, nativePointer, 1);" << endl | |
2639 << INDENT << "return " << fromObject(java_class->typeEntry(), "ptr") << endl | |
2640 << "}" << endl; | |
2641 } | |
2642 } | |
2643 | |
2644 void CppImplGenerator::writeFromArrayFunction(QTextStream &s, const AbstractMetaClass *java_class) | |
2645 { | |
2646 s << jni_function_signature(java_class->package(), | |
2647 java_class->name(), | |
2648 "nativePointerArray", | |
2649 "jobject"); | |
2650 s << endl | |
2651 << "(JNIEnv *__jni_env," << endl | |
2652 << " jclass," << endl | |
2653 << " jobjectArray array)" << endl | |
2654 << "{" << endl; | |
2655 { | |
2656 Indentation indent(INDENT); | |
2657 s << INDENT << "return qtjambi_array_to_nativepointer(__jni_env, " << endl | |
2658 << INDENT << " array, " << endl | |
2659 << INDENT << " sizeof(" | |
2660 << java_class->qualifiedCppName() << "));" << endl; | |
2661 } | |
2662 s << "}" << endl; | |
2663 } | |
2664 | |
2665 | |
2666 void CppImplGenerator::writeInterfaceCastFunction(QTextStream &s, | |
2667 const AbstractMetaClass *java_class, | |
2668 const AbstractMetaClass *interface) | |
2669 { | |
2670 Q_ASSERT(interface->isInterface()); | |
2671 const InterfaceTypeEntry *ie = static_cast<const InterfaceTypeEntry *>(interface->typeEntry()); | |
2672 QString interface_name = ie->origin()->targetLangName(); | |
2673 | |
2674 s << endl | |
2675 << jni_function_signature(java_class->package(), | |
2676 java_class->name(), | |
2677 QString("__qt_cast_to_%1").arg(interface_name), | |
2678 "jlong", | |
2679 "__J"); | |
2680 | |
2681 s << endl | |
2682 << "(JNIEnv *," << endl | |
2683 << " jobject," << endl | |
2684 << " jlong ptr)" << endl | |
2685 << "{" << endl | |
2686 << " return (jlong) (" << interface->primaryInterfaceImplementor()->qualifiedCppName() << " *) " | |
2687 << "(" << java_class->qualifiedCppName() << " *) ptr;" << endl | |
2688 << "}" << endl; | |
2689 } | |
2690 | |
2691 bool CppImplGenerator::writeConversionRule(QTextStream &s, | |
2692 TypeSystem::Language target_language, | |
2693 const AbstractMetaFunction *java_function, | |
2694 int argument_index, | |
2695 const QString &qt_name, | |
2696 const QString &java_name) | |
2697 { | |
2698 if (argument_index < 0 || java_function == 0) | |
2699 return false; | |
2700 | |
2701 QString conversion_rule = java_function->conversionRule(target_language, argument_index); | |
2702 | |
2703 if (!conversion_rule.isEmpty()) { | |
2704 QString qt_name_var; | |
2705 QString java_name_var; | |
2706 | |
2707 if ((argument_index == 0 && target_language == TypeSystem::NativeCode) | |
2708 || (argument_index != 0 && target_language == TypeSystem::ShellCode)) { | |
2709 qt_name_var = "%in"; | |
2710 java_name_var = "%out"; | |
2711 } else { | |
2712 qt_name_var = "%out"; | |
2713 java_name_var = "%in"; | |
2714 } | |
2715 | |
2716 conversion_rule = conversion_rule.replace(qt_name_var, qt_name) | |
2717 .replace(java_name_var, java_name); | |
2718 | |
2719 AbstractMetaArgumentList arguments = java_function->arguments(); | |
2720 for (int i=0; i<arguments.size(); ++i) { | |
2721 conversion_rule = conversion_rule.replace("%" + QString::number(i+1), | |
2722 arguments.at(i)->indexedName()); | |
2723 } | |
2724 | |
2725 QStringList lines = conversion_rule.split("\n"); | |
2726 foreach (QString line, lines) { | |
2727 s << INDENT << line.trimmed() << endl; | |
2728 } | |
2729 | |
2730 return true; | |
2731 } else { | |
2732 return false; | |
2733 } | |
2734 } | |
2735 | |
2736 | |
2737 void CppImplGenerator::writeJavaToQt(QTextStream &s, | |
2738 const AbstractMetaClass *java_class, | |
2739 const AbstractMetaType *function_return_type, | |
2740 const QString &qt_name, | |
2741 const QString &java_name, | |
2742 const AbstractMetaFunction *java_function, | |
2743 int argument_index) | |
2744 { | |
2745 // Conversion to C++: Shell code for return values, native code for arguments | |
2746 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::ShellCode : TypeSystem::NativeCode; | |
2747 if (writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) | |
2748 return; | |
2749 | |
2750 s << INDENT << shellClassName(java_class) << " *" << qt_name << " = (" | |
2751 << shellClassName(java_class) << " *) "; | |
2752 if (java_class->isQObject()) | |
2753 s << "qtjambi_to_qobject"; | |
2754 else | |
2755 s << "qtjambi_to_object"; | |
2756 s << "(__jni_env, " << java_name << ");" << endl; | |
2757 if (java_class->isQObject()) { | |
2758 // ### throw exceptions when objects are null... | |
2759 s << INDENT << "if (!" << qt_name << ") " | |
2760 << default_return_statement_java(function_return_type) << ";" << endl << endl; | |
2761 } | |
2762 } | |
2763 | |
2764 | |
2765 void CppImplGenerator::writeJavaToQt(QTextStream &s, | |
2766 const AbstractMetaType *java_type, | |
2767 const QString &qt_name, | |
2768 const QString &java_name, | |
2769 const AbstractMetaFunction *java_function, | |
2770 int argument_index, | |
2771 Option options) | |
2772 { | |
2773 // Conversion to C++: Shell code for return values, native code for arguments | |
2774 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::ShellCode : TypeSystem::NativeCode; | |
2775 if (java_function && writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) | |
2776 return; | |
2777 | |
2778 if (java_type == 0) { | |
2779 QString warn = QString("no conversion possible for argument '%1' in function '%2::%3' for " | |
2780 "language '%4'") | |
2781 .arg(argument_index) | |
2782 .arg(java_function->implementingClass()->name()) | |
2783 .arg(java_function->name()) | |
2784 .arg(int(lang)); | |
2785 ReportHandler::warning(warn); | |
2786 return; | |
2787 } | |
2788 if (java_type->name() == "QModelIndex") { | |
2789 s << INDENT << "QModelIndex " << qt_name << " = qtd_to_QModelIndex(" | |
2790 << java_name << ");" << endl; | |
2791 } else if (java_type->typeEntry()->isStructInD()) { | |
2792 // empty | |
2793 } else if (java_type->typeEntry() && java_type->typeEntry()->qualifiedCppName() == "QString") { | |
2794 s << INDENT << "QString " << qt_name | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2795 << " = " << QString("QString::fromUtf8((const char *)%1.ptr, %1.length);").arg(java_name) << endl; |
1 | 2796 } else if (java_type->isJObjectWrapper()) { |
2797 s << INDENT << "JObjectWrapper " << qt_name | |
2798 << " = qtjambi_to_jobjectwrapper(__jni_env, " << java_name << ");" << endl; | |
2799 } else if (java_type->isVariant()) { | |
2800 s << INDENT << "QVariant " << qt_name | |
2801 << " = " << java_name << " == NULL ? QVariant() : QVariant(*" << java_name << ");" << endl; | |
2802 } else if (java_type->isArray() && java_type->arrayElementType()->isPrimitive()) { | |
2803 AbstractMetaType *elementType = java_type->arrayElementType(); | |
2804 | |
2805 // ### Don't assert on wrong array lengths | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2806 // s << INDENT << "Q_ASSERT(__jni_env->GetArrayLength((jarray) " << java_name << ") == " << java_type->arrayElementCount() << ");" << endl; |
1 | 2807 s << INDENT; |
2808 writeTypeInfo(s, elementType); | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2809 s << " *" << qt_name << " = ("; |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2810 writeTypeInfo(s, elementType); |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2811 s << "*) " << java_name << ";" << endl; |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2812 /* |
1 | 2813 s << INDENT << "__jni_env->" << getXxxArrayRegion(elementType) << "( (" << translateType(java_type, options) |
2814 << ")" << java_name << ", 0, " << java_type->arrayElementCount() << ", " | |
2815 << "(" << translateType(elementType, options) << " *" << ")" | |
2816 << qt_name << ");" << endl; | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2817 */ |
1 | 2818 } else if (java_type->isArray()) { |
2819 AbstractMetaType *elementType = java_type->arrayElementType(); | |
2820 | |
2821 s << INDENT << "Q_ASSERT(__jni_env->GetArrayLength((jarray) " << java_name << ") == " << java_type->arrayElementCount() << ");" << endl; | |
2822 writeTypeInfo(s, elementType); | |
2823 s << "[" << java_type->arrayElementCount() << "]" << qt_name << ";" << endl; | |
2824 | |
2825 for (int i=0; i<java_type->arrayElementCount(); ++i) { | |
2826 writeJavaToQt(s, elementType, qt_name + "[" + QString::number(i) + "]", | |
2827 "__jni_env->GetObjectArrayElement(" + java_name + ", " + QString::number(i) + ")", 0, -1, options); | |
2828 } | |
2829 | |
2830 } else if (java_type->isTargetLangString()) { | |
2831 s << INDENT << "QString " << qt_name | |
2832 << " = " << "QString::fromUtf8(" << java_name << ", " << java_name << "_size);" << endl; | |
2833 // qtd << " = qtjambi_to_qstring(__jni_env, (jstring) " << java_name << ");" << endl; | |
2834 | |
2835 } else if (java_type->isTargetLangChar()) { | |
2836 s << INDENT << "QChar " << qt_name | |
2837 << " = (ushort)" << java_name << ";" << endl; | |
2838 | |
2839 } else if (java_type->isEnum() || java_type->isFlags()) { | |
2840 | |
2841 bool written = false; | |
2842 if (java_type->isEnum()) { | |
2843 AbstractMetaEnum *java_enum = | |
2844 m_classes.findEnum(static_cast<const EnumTypeEntry *>(java_type->typeEntry())); | |
2845 if (java_enum && !java_enum->isPublic()) { | |
2846 | |
2847 s << INDENT << "int " << qt_name << " = "; | |
2848 written = true; | |
2849 } | |
2850 } | |
2851 | |
2852 if (!written) { | |
2853 QString qualified_name = java_type->typeEntry()->qualifiedCppName(); | |
2854 s << INDENT << qualified_name << " " << qt_name | |
2855 << " = (" << qualified_name << ") "; | |
2856 } | |
2857 | |
2858 if ((options & EnumAsInts) == 0 && (java_type->isTargetLangEnum() || java_type->isTargetLangFlags())) { | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
2859 s << java_name << ";" << endl; |
1 | 2860 |
2861 } else if (options & BoxedPrimitive) { | |
2862 const PrimitiveTypeEntry *pentry = TypeDatabase::instance()->findTargetLangPrimitiveType("int"); | |
2863 Q_ASSERT(pentry); | |
2864 | |
2865 s << java_name << ";" << endl; | |
2866 | |
2867 } else { | |
2868 s << java_name << ';' << endl; | |
2869 } | |
2870 | |
2871 } else if (java_type->isContainer()) { | |
2872 writeJavaToQtContainer(s, java_type, qt_name, java_name, 0, -1); | |
2873 | |
2874 } else if (java_type->isThread()) { | |
2875 s << INDENT << "QThread *" << qt_name << " = qtjambi_to_thread(__jni_env, " << java_name | |
2876 << ");" << endl; | |
2877 | |
2878 } else if (java_type->typeEntry()->isCustom()) { | |
2879 const CustomTypeEntry *custom_type = | |
2880 static_cast<const CustomTypeEntry *>(java_type->typeEntry()); | |
2881 s << INDENT; | |
2882 custom_type->generateCppJavaToQt(s, java_type, "__jni_env", qt_name, java_name); | |
2883 s << ";" << endl; | |
2884 | |
2885 } else { | |
2886 | |
2887 const TypeEntry *type = java_type->typeEntry(); | |
2888 QString class_name = type->name(); | |
2889 QString qualified_class_name = fixCppTypeName(type->qualifiedCppName()); | |
2890 | |
2891 // Declaration and the c-cast | |
2892 s << INDENT; | |
2893 writeTypeInfo(s, java_type); | |
2894 s << ' ' << qt_name << " = ("; | |
2895 writeTypeInfo(s, java_type); | |
2896 s << ") "; | |
2897 | |
2898 if (java_type->isPrimitive()) { | |
2899 if (options & BoxedPrimitive) { | |
2900 const PrimitiveTypeEntry *pentry = static_cast<const PrimitiveTypeEntry *>(type); | |
2901 //std::cout << "---error_here " << type->targetLangName().toStdString() << " \n"; | |
2902 //std::cout << "----func_here " << java_function->marshalledName().toStdString() << " \n"; | |
2903 | |
2904 if (!pentry->preferredConversion()) | |
2905 pentry = TypeDatabase::instance()->findTargetLangPrimitiveType(pentry->targetLangName()); | |
2906 Q_ASSERT(pentry); | |
2907 | |
2908 s << java_name << ";" << endl; | |
2909 | |
2910 } else if ((options & GlobalRefJObject) && type->jniName() == QLatin1String("jobject")) { | |
2911 s << "__jni_env->NewGlobalRef(" << java_name << ");" << endl; | |
2912 } else { | |
2913 s << java_name << ';' << endl; | |
2914 } | |
2915 | |
2916 #if 0 | |
2917 } else if (java_type->isEnum()) { | |
2918 s << "qtjambi_to_enum(__jni_env, " << java_name << ");" << endl; | |
2919 #endif | |
2920 | |
2921 } else if ((java_type->isQObject() || java_type->isObject()) | |
2922 && static_cast<const ObjectTypeEntry *>(type)->designatedInterface()) { | |
2923 /* qtd const InterfaceTypeEntry *ie = | |
2924 static_cast<const ObjectTypeEntry *>(type)->designatedInterface(); | |
2925 s << "qtjambi_to_interface(__jni_env, "; | |
2926 | |
2927 // This cast is only valid if we're dealing with a native id | |
2928 if ((options & UseNativeIds) == UseNativeIds) | |
2929 s << "(QtJambiLink *)"; | |
2930 */ | |
2931 s << java_name << ";" << endl; | |
2932 /* qtd | |
2933 s << "\"" << ie->targetLangName() << "\", \"" | |
2934 << ie->javaPackage().replace(".", "/") << "/\", " | |
2935 << "\"__qt_cast_to_" << type->targetLangName() << "\");" << endl; | |
2936 */ | |
2937 } else if (java_type->isObject() || java_type->isQObject() || java_type->isNativePointer()) { | |
2938 if (java_type->isReference()) { | |
2939 s << "* (" << qualified_class_name << " " | |
2940 << QString(java_type->actualIndirections(), '*') << ") "; | |
2941 } | |
2942 | |
2943 if (java_type->isNativePointer()) { | |
2944 /* qtd s << "qtjambi_to_cpointer(" | |
2945 << "__jni_env, " | |
2946 << java_name << ", " | |
2947 << java_type->actualIndirections() << ");" << endl; */ | |
2948 s << java_name << ";" << endl; // qtd | |
2949 }/* qtd else if (java_type->isQObject()) { | |
2950 if ((options & UseNativeIds) == 0) | |
2951 s << "qtjambi_to_qobject(__jni_env, "; | |
2952 else | |
2953 s << "qtjambi_from_jlong("; | |
2954 s << java_name; | |
2955 s << ");" << endl; | |
2956 }*/ else { | |
2957 /* qtd if ((options & UseNativeIds) == 0) | |
2958 s << "qtjambi_to_object(__jni_env, "; | |
2959 else | |
2960 s << "qtjambi_from_jlong("; | |
2961 */ s << java_name; | |
2962 s << ";" << endl; // + | |
2963 // qtd s << ");" << endl; | |
2964 } | |
2965 | |
2966 } else { | |
2967 // Return values... | |
2968 if (argument_index == 0) { | |
2969 s << "(" << java_name << " != 0 ? *(" << qualified_class_name << " *)"; | |
2970 /* qtd if ((options & UseNativeIds) == 0) | |
2971 s << "qtjambi_to_object(__jni_env, "; | |
2972 else | |
2973 s << "qtjambi_from_jlong("; | |
2974 */ s << java_name; | |
2975 s << " : " << qualified_class_name << "());" << endl; | |
2976 } else { | |
2977 s << "*" | |
2978 << "(" << qualified_class_name << " *)"; | |
2979 bool null_check = false; | |
2980 /* qtd if ((options & UseNativeIds) == 0) { | |
2981 s << "qtjambi_to_object(__jni_env, "; | |
2982 } else if (hasDefaultConstructor(java_type)) { | |
2983 null_check = true; | |
2984 s << "(" << java_name << " != 0 ? qtjambi_from_jlong("; | |
2985 } else { | |
2986 s << "qtjambi_from_jlong("; | |
2987 } | |
2988 */ s << java_name; | |
2989 // qtd s << ")"; | |
2990 | |
2991 if (null_check) | |
2992 s << " : default_" << QString(qualified_class_name).replace("::", "_") << "())"; | |
2993 s << ";" << endl; | |
2994 } | |
2995 | |
2996 } | |
2997 } | |
2998 // qtd s << INDENT << "QTJAMBI_EXCEPTION_CHECK(__jni_env);" << endl; | |
2999 } | |
3000 | |
3001 void CppImplGenerator::writeQtToJava(QTextStream &s, | |
3002 const AbstractMetaType *java_type, | |
3003 const QString &qt_name, | |
3004 const QString &java_name, | |
3005 const AbstractMetaFunction *java_function, | |
3006 int argument_index, | |
3007 Option option) | |
3008 { | |
3009 | |
3010 // Conversion to Java: Native code for return values, shell code for arguments | |
3011 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::NativeCode : TypeSystem::ShellCode; | |
3012 /* qtd if (java_function && writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) | |
3013 return; | |
3014 */ | |
3015 if (java_type == 0) { | |
3016 QString warn = QString("no conversion possible for argument '%1' in function '%2::%3' for " | |
3017 "language '%4'") | |
3018 .arg(argument_index) | |
3019 .arg(java_function->implementingClass()->name()) | |
3020 .arg(java_function->name()) | |
3021 .arg(int(lang)); | |
3022 ReportHandler::warning(warn); | |
3023 return; | |
3024 } | |
3025 | |
3026 if (java_type->name() == "QModelIndex") { | |
3027 QString prefix = "*"; | |
3028 if (option & BoxedPrimitive) | |
3029 s << INDENT << "QModelIndexAccessor tmp_index = qtd_from_QModelIndex(" << qt_name << ");" << endl | |
3030 << INDENT << "QModelIndexAccessor *" << java_name << " = &tmp_index;" << endl; | |
3031 else | |
3032 s << INDENT << "*" << java_name << " = qtd_from_QModelIndex(" << qt_name << ");" << endl; | |
3033 | |
81 | 3034 } else if (java_type->typeEntry()->isStructInD()) { |
3035 if (option & BoxedPrimitive) { | |
3036 s << INDENT << java_type->typeEntry()->name() << " *" << java_name << " = (" | |
3037 << java_type->typeEntry()->name() << " *) &" << qt_name << ";" << endl; | |
3038 } else { | |
3039 s << INDENT << "*" << java_name << " = " << qt_name << ";" << endl; | |
3040 } | |
1 | 3041 } else if (java_type->isArray() && java_type->arrayElementType()->isPrimitive()) { |
3042 AbstractMetaType *elementType = java_type->arrayElementType(); | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3043 /* qtd |
1 | 3044 s << INDENT << translateType(java_type, option) << " " << java_name << " = __jni_env->" << newXxxArray(elementType) |
3045 << "(" << java_type->arrayElementCount() << ");" << endl; | |
3046 | |
3047 s << INDENT << "__jni_env->" << setXxxArrayRegion(elementType) << "(" | |
3048 << "(" << translateType(java_type, option) << ")" << java_name | |
3049 << ", 0, " << java_type->arrayElementCount() << ", " | |
3050 << "(" << translateType(elementType, option) << " *" << ")" | |
3051 << qt_name << ");" << endl; | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3052 */ |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3053 s << INDENT << translateType(java_type, option) << " " << java_name << " = " << qt_name << ";" <<endl; |
1 | 3054 } else if (java_type->isArray()) { |
3055 AbstractMetaType *elementType = java_type->arrayElementType(); | |
3056 | |
3057 s << INDENT << "jobject " << java_name << " = __jni_env->NewObjectArray(" | |
3058 << java_type->arrayElementCount() << ");" << endl; | |
3059 | |
3060 s << "jobject __qt_element = 0;"; | |
3061 | |
3062 for (int i=0; i<java_type->arrayElementCount(); ++i) { | |
3063 writeQtToJava(s, elementType, qt_name + "[" + QString::number(i) + "]", | |
3064 "__qt_element", 0, -1, option); | |
3065 s << "__jni_env->SetObjectArrayElement((jobjectArray) " << java_name << ", " | |
3066 << i << ", __qt_element);" << endl; | |
3067 } | |
3068 | |
3069 } else if (java_type->isPrimitive()) { | |
3070 const PrimitiveTypeEntry *type = | |
3071 static_cast<const PrimitiveTypeEntry *>(java_type->typeEntry()); | |
3072 | |
3073 Q_ASSERT(type); | |
3074 QString ret_val; | |
3075 if (java_function) | |
3076 ret_val = jniReturnName(java_function); | |
3077 else | |
3078 ret_val = fixCppTypeName(java_type->typeEntry()->qualifiedCppName()); | |
3079 s << INDENT << ret_val << " " << java_name << " = " << qt_name << ";" << endl; | |
3080 } else if (java_type->isJObjectWrapper()) { | |
3081 s << INDENT << "jobject " << java_name << " = qtjambi_from_jobjectwrapper(__jni_env, " | |
3082 << qt_name << ");" << endl; | |
3083 } else if (java_type->isVariant()) { | |
3084 s << INDENT << "QVariant *" << java_name | |
3085 << " = new QVariant(" << qt_name << ");" << endl; | |
3086 } else if (java_type->isTargetLangString()) { | |
35 | 3087 if(java_type->typeEntry()->qualifiedCppName() == "QStringRef") { |
3088 s << INDENT << "const QString *str_ref = " << qt_name << ".string();" << endl | |
3089 << INDENT << "if(str_ref)" << endl | |
253 | 3090 << INDENT << " qtd_toUtf8(str_ref->utf16(), str_ref->size(), " << java_name << ");" << endl |
35 | 3091 << INDENT << "else {" << endl |
3092 << INDENT << " QString empty_str;" << endl | |
253 | 3093 << INDENT << " qtd_toUtf8(empty_str.utf16(), empty_str.size(), " << java_name << ");" << endl |
35 | 3094 << INDENT << "}" << endl; |
3095 } else { | |
253 | 3096 s << INDENT << QString("qtd_toUtf8(%1.utf16(), %1.size(), %2);").arg(qt_name, java_name) << endl; |
35 | 3097 } |
1 | 3098 } else if (java_type->isTargetLangChar()) { |
3099 s << INDENT << "jchar " << java_name << " = " << qt_name << ".unicode();" << endl; | |
3100 | |
3101 } else if (java_type->isIntegerEnum() || java_type->isIntegerFlags() | |
3102 || ((option & EnumAsInts) && (java_type->isEnum() || java_type->isFlags()))) { | |
3103 // } else if (java_type->isEnum() || java_type->isFlags()) { | |
3104 | |
3105 // if (option & EnumAsInts) { | |
3106 // qDebug() << java_type->name() << "should be int..."; | |
3107 // } | |
3108 | |
3109 /* if (option & BoxedPrimitive) { | |
3110 s << INDENT << "jobject " << java_name << " = qtjambi_from_int(__jni_env, " | |
3111 << qt_name << ");" << endl; | |
3112 } else */{ | |
3113 s << INDENT << "int " << java_name << " = " << qt_name << ";" << endl; | |
3114 } | |
3115 | |
3116 } else if (java_type->isTargetLangEnum()) { | |
3117 Q_ASSERT((option & EnumAsInts) == 0); | |
3118 const EnumTypeEntry *et = static_cast<const EnumTypeEntry *>(java_type->typeEntry()); | |
3119 s << INDENT << "int " << java_name << " = " << qt_name << ";" << endl; | |
3120 | |
3121 } else if (java_type->isTargetLangFlags()) { | |
3122 Q_ASSERT((option & EnumAsInts) == 0); | |
3123 const FlagsTypeEntry *ft = static_cast<const FlagsTypeEntry *>(java_type->typeEntry()); | |
3124 s << INDENT << "jobject " << java_name << " = qtjambi_from_flags(__jni_env, " | |
3125 << qt_name << ", \"" << ft->javaPackage().replace('.', '/') << '/' | |
3126 << ft->originator()->javaQualifier() << '$' << ft->targetLangName() << "\");" << endl; | |
3127 | |
3128 } else if (java_type->isContainer()) { | |
3129 writeQtToJavaContainer(s, java_type, qt_name, java_name, 0, -1); | |
3130 | |
3131 } else if (java_type->isThread()) { | |
3132 s << INDENT << "jobject " << java_name << " = qtjambi_from_thread(__jni_env, " << qt_name | |
3133 << ");" << endl; | |
3134 | |
3135 } else if (!java_type->isNativePointer() && java_type->typeEntry()->isCustom()) { | |
3136 s << INDENT; | |
3137 static_cast<const CustomTypeEntry *>(java_type->typeEntry()) | |
3138 ->generateCppQtToJava(s, java_type, "__jni_env", qt_name, java_name); | |
3139 s << ";" << endl; | |
3140 | |
3141 } else { | |
3142 QString return_type; | |
3143 if (java_function) | |
3144 return_type = jniReturnName(java_function); | |
3145 else { | |
3146 return_type = jniReturnType(java_type); | |
3147 return_type = fixCppTypeName(return_type); | |
3148 // return_type = fixCppTypeName(java_type->typeEntry()->qualifiedCppName()); | |
3149 } | |
3150 /* if( (java_type->isValue() && !java_type->typeEntry()->isStructInD()) | |
3151 || java_type->isObject() ) | |
3152 s << INDENT << return_type << " *" << java_name << " = (" << return_type << "*) "; | |
3153 else*/ | |
3154 s << INDENT << return_type << " " << java_name << " = (" << return_type << ") "; | |
3155 | |
3156 if (java_type->isQObject()) { | |
3157 /* qtd s << "qtjambi_from_qobject(__jni_env, " << "(QObject *) "; | |
3158 | |
3159 if (java_type->isReference() && java_type->indirections() == 0) | |
3160 s << "&"; | |
3161 | |
3162 s << qt_name | |
3163 << ", \"" << java_type->typeEntry()->lookupName() << "\"" | |
3164 << ", \"" << java_type->package().replace(".", "/") << "/\"" | |
3165 << ");" << endl; | |
3166 */ | |
3167 s << qt_name << ";" << endl; | |
3168 | |
3169 #if 0 | |
3170 } else if (java_type->isEnum()) { | |
3171 | |
3172 const EnumTypeEntry *et = static_cast<const EnumTypeEntry *>(java_type->typeEntry()); | |
3173 s << "qtjambi_from_enum(__jni_env, " << qt_name << ", \"" | |
3174 << et->javaQualifier() << "$" << et->targetLangName() << "\");" << endl; | |
3175 #endif | |
3176 } else if (java_type->isNativePointer()) { | |
3177 /* qtd s << "qtjambi_from_cpointer(__jni_env, "; | |
3178 if (java_type->isReference()) | |
3179 s << "&"; | |
3180 s << qt_name << ", " << nativePointerType(java_type) << ", " | |
3181 << java_type->actualIndirections() << ");" << endl; | |
3182 */ | |
3183 if (java_type->isReference()) | |
3184 s << "&"; | |
3185 s << qt_name << ";" << "// qtjambi_from_cpointer" << endl; | |
3186 } else if (java_type->isValue()) { | |
3187 // qtd s << fromObject(java_type->typeEntry(), "&" + qt_name) << endl; | |
3188 s << "new " << java_type->typeEntry()->qualifiedCppName() << "(" << qt_name << ");" << endl; | |
3189 } else { | |
3190 // qtd s << fromObject(java_type->typeEntry(), | |
3191 // qtd (java_type->isReference() ? "&" : "") + qt_name) << endl; | |
3192 s << qt_name << ";" << endl; | |
3193 } | |
3194 } | |
3195 | |
3196 } | |
3197 | |
3198 QString CppImplGenerator::getTypeName(const TypeEntry *entry, Option option) | |
3199 { | |
3200 if(entry->isEnum() && (option & EnumAsInts)) | |
3201 return "int"; | |
3202 | |
3203 return entry->lookupName(); | |
3204 } | |
3205 | |
3206 void CppImplGenerator::writeQtToJavaContainer(QTextStream &s, | |
3207 const AbstractMetaType *java_type, | |
3208 const QString &qt_name, | |
3209 const QString &java_name, | |
3210 const AbstractMetaFunction *java_function, | |
3211 int argument_index) | |
3212 { | |
3213 // Language for conversion to Java: Native code for return values and Shell code for arguments | |
3214 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::NativeCode : TypeSystem::ShellCode; | |
3215 if (java_function && writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) | |
3216 return; | |
3217 | |
3218 if (java_type == 0) { | |
3219 QString warn = QString("no conversion possible for argument '%1' in function '%2::%3' for " | |
3220 "language '%4'") | |
3221 .arg(argument_index) | |
3222 .arg(java_function->implementingClass()->name()) | |
3223 .arg(java_function->name()) | |
3224 .arg(int(lang)); | |
3225 ReportHandler::warning(warn); | |
3226 return; | |
3227 } | |
3228 | |
3229 Q_ASSERT(java_type->isContainer()); | |
3230 const ContainerTypeEntry *type = | |
3231 static_cast<const ContainerTypeEntry *>(java_type->typeEntry()); | |
3232 | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3233 if (type->type() == ContainerTypeEntry::VectorContainer |
1 | 3234 || type->type() == ContainerTypeEntry::LinkedListContainer |
3235 || type->type() == ContainerTypeEntry::StackContainer | |
3236 || type->type() == ContainerTypeEntry::SetContainer | |
3237 || type->type() == ContainerTypeEntry::QueueContainer) { | |
3238 | |
3239 Q_ASSERT(java_type->instantiations().size() == 1); | |
3240 AbstractMetaType *targ = java_type->instantiations().first(); | |
3241 | |
3242 QString cls_name = getTypeName(targ->typeEntry(), EnumAsInts); | |
3243 cls_name.remove("_ConcreteWrapper"); | |
3244 | |
3245 s << endl | |
3246 << INDENT; | |
3247 | |
3248 switch (type->type()) { | |
3249 case ContainerTypeEntry::LinkedListContainer: | |
3250 case ContainerTypeEntry::QueueContainer: | |
3251 s << "qtjambi_linkedlist_new(__jni_env)"; | |
3252 break; | |
3253 case ContainerTypeEntry::StackContainer: | |
3254 s << "qtjambi_stack_new(__jni_env)"; | |
3255 break; | |
3256 case ContainerTypeEntry::SetContainer: | |
3257 s << "qtjambi_hashset_new(__jni_env)"; | |
3258 break; | |
3259 default: | |
3260 s << "qtd_allocate_" << cls_name | |
3261 << "_array(" << java_name << ", " << qt_name << ".size())"; | |
3262 break; | |
3263 } | |
3264 | |
3265 s << ";" << endl | |
3266 << INDENT; | |
3267 | |
3268 | |
3269 writeTypeInfo(s, java_type, ForceValueType); | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
148
diff
changeset
|
3270 QString index = "i_" + qt_name; |
1 | 3271 s << "::const_iterator " << qt_name << "_end_it = " << qt_name << ".constEnd();" << endl |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
148
diff
changeset
|
3272 << INDENT << QString("int %0 = 0;").arg(index) << endl |
1 | 3273 << INDENT; |
3274 s << "for ("; | |
3275 writeTypeInfo(s, java_type, ForceValueType); | |
3276 s << "::const_iterator " << qt_name << "_it = " << qt_name << ".constBegin(); " | |
3277 << qt_name << "_it != " << qt_name << "_end_it; ++" << qt_name << "_it) {" << endl; | |
3278 { | |
3279 Indentation indent(INDENT); | |
3280 s << INDENT; | |
3281 writeTypeInfo(s, targ); | |
3282 s << " __qt_tmp = *" << qt_name << "_it;" << endl; | |
3283 | |
3284 if(targ->isTargetLangString()) | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
148
diff
changeset
|
3285 s << INDENT << "void *__java_tmp = qtd_string_from_array(" << java_name << ", " << index << ");" << endl; |
1 | 3286 |
3287 writeQtToJava(s, targ, "__qt_tmp", "__java_tmp", 0, -1, BoxedPrimitive); | |
3288 | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
148
diff
changeset
|
3289 s << INDENT << "qtd_assign_" << cls_name << "_array_element(" << java_name << ", " << index << ", __java_tmp);" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
148
diff
changeset
|
3290 s << INDENT << "++" << index << ";" << endl; |
1 | 3291 } |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
148
diff
changeset
|
3292 s << INDENT << "}" << endl; |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3293 |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3294 } else if (type->isQList()) { |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3295 // QList<QObject*> & list2 = (*(QList<QObject*> *)nativeId); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3296 writeTypeInfo(s, java_type, ForceValueType); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3297 s << "&" << java_name << "_tmp = (*("; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3298 writeTypeInfo(s, java_type, ForceValueType); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3299 s << "*)" << java_name << ");" << endl |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3300 << INDENT << java_name << "_tmp = " << qt_name << ";" << endl; |
1 | 3301 |
3302 } else if (type->type() == ContainerTypeEntry::PairContainer) { | |
3303 QList<AbstractMetaType *> args = java_type->instantiations(); | |
3304 Q_ASSERT(args.size() == 2); | |
3305 | |
3306 s << INDENT << "jobject " << java_name << ";" << endl | |
3307 << INDENT << "{" << endl; | |
3308 { | |
3309 Indentation indent(INDENT); | |
3310 writeQtToJava(s, args.at(0), qt_name + ".first", "__java_tmp_first", 0, -1, BoxedPrimitive); | |
3311 writeQtToJava(s, args.at(1), qt_name + ".second", "__java_tmp_second", 0, -1, BoxedPrimitive); | |
3312 s << INDENT << java_name << " = qtjambi_pair_new(__jni_env, " | |
3313 << "__java_tmp_first, __java_tmp_second);" << endl; | |
3314 } | |
3315 | |
3316 s << INDENT << "}" << endl; | |
3317 | |
3318 } else if (type->type() == ContainerTypeEntry::MultiMapContainer) { | |
3319 | |
3320 Q_ASSERT(java_type->instantiations().size() == 2); | |
3321 AbstractMetaType *targ_key = java_type->instantiations().at(0); | |
3322 AbstractMetaType *targ_val = java_type->instantiations().at(1); | |
3323 | |
3324 s << endl | |
3325 << INDENT << "jobject " << java_name << " = qtjambi_treemap_new(__jni_env, " << qt_name << ".keys().size());" << endl | |
3326 << INDENT << "QList<"; | |
3327 writeTypeInfo(s, targ_key); | |
3328 s << "> __qt_keys = " << qt_name << ".keys();" << endl | |
3329 << INDENT << "for (int i=0; i<__qt_keys.size(); ++i) {" << endl; | |
3330 { | |
3331 Indentation indent(INDENT); | |
3332 | |
3333 s << INDENT; | |
3334 writeTypeInfo(s, targ_key); | |
3335 s << " __qt_tmp_key = __qt_keys.at(i);" << endl; | |
3336 writeQtToJava(s, targ_key, "__qt_tmp_key", "__java_tmp_key", 0, -1, BoxedPrimitive); | |
3337 | |
3338 s << INDENT << "QList<"; | |
3339 writeTypeInfo(s, targ_val); | |
3340 s << "> __qt_values = " << qt_name << ".values(__qt_tmp_key);" << endl | |
3341 << INDENT << "jobject __java_value_list = qtjambi_arraylist_new(__jni_env, __qt_values.size());" << endl | |
3342 << INDENT << "for (int j=0; j<__qt_values.size(); ++j) {" << endl; | |
3343 { | |
3344 Indentation indent(INDENT); | |
3345 | |
3346 s << INDENT; | |
3347 writeTypeInfo(s, targ_val); | |
3348 s << " __qt_tmp_val = __qt_values.at(j);" << endl; | |
3349 writeQtToJava(s, targ_val, "__qt_tmp_val", "__java_tmp_val", 0, -1, BoxedPrimitive); | |
3350 | |
3351 s << INDENT << "qtjambi_collection_add(__jni_env, __java_value_list, __java_tmp_val);" << endl; | |
3352 } | |
3353 s << INDENT << "}" << endl | |
3354 << INDENT << "qtjambi_map_put(__jni_env, " << java_name << ", __java_tmp_key, __java_value_list);" << endl; | |
3355 } | |
3356 s << INDENT << "}" << endl; | |
3357 | |
3358 } else if (type->type() == ContainerTypeEntry::MapContainer | |
3359 || type->type() == ContainerTypeEntry::HashContainer) { | |
3360 QString constructor = type->type() == ContainerTypeEntry::MapContainer | |
3361 ? "qtjambi_treemap_new" | |
3362 : "qtjambi_hashmap_new"; | |
3363 | |
3364 Q_ASSERT(java_type->instantiations().size() == 2); | |
3365 AbstractMetaType *targ_key = java_type->instantiations().at(0); | |
3366 AbstractMetaType *targ_val = java_type->instantiations().at(1); | |
3367 | |
3368 s << endl | |
3369 << INDENT << "jobject " << java_name << " = " << constructor << "(__jni_env, " << qt_name | |
3370 << ".size());" << endl | |
3371 << INDENT; | |
3372 writeTypeInfo(s, java_type, Option(ExcludeReference | ExcludeConst)); | |
3373 s << "::const_iterator it;" << endl | |
3374 << INDENT << "for (it=" << qt_name << ".constBegin(); it!=" << qt_name << ".constEnd(); ++it) {" << endl; | |
3375 { | |
3376 Indentation indent(INDENT); | |
3377 s << INDENT; | |
3378 writeTypeInfo(s, targ_key); | |
3379 s << " __qt_tmp_key = it.key();" << endl | |
3380 << INDENT; | |
3381 writeTypeInfo(s, targ_val); | |
3382 s << " __qt_tmp_val = it.value();" << endl; | |
3383 writeQtToJava(s, targ_key, "__qt_tmp_key", "__java_tmp_key", 0, -1, BoxedPrimitive); | |
3384 writeQtToJava(s, targ_val, "__qt_tmp_val", "__java_tmp_val", 0, -1, BoxedPrimitive); | |
3385 s << INDENT << "qtjambi_map_put(__jni_env, " << java_name | |
3386 << ", __java_tmp_key, __java_tmp_val);" << endl; | |
3387 } | |
3388 s << INDENT << "}" << endl; | |
3389 | |
3390 } else { | |
3391 ReportHandler::warning(QString("unable to generate container type %1, type=%2") | |
3392 .arg(java_type->name()).arg(type->type())); | |
3393 } | |
3394 | |
3395 // qtd s << INDENT << "QTJAMBI_EXCEPTION_CHECK(__jni_env);" << endl; | |
3396 } | |
3397 | |
3398 | |
3399 void CppImplGenerator::writeJavaToQtContainer(QTextStream &s, | |
3400 const AbstractMetaType *java_type, | |
3401 const QString &qt_name, | |
3402 const QString &java_name, | |
3403 const AbstractMetaFunction *java_function, | |
3404 int argument_index) | |
3405 { | |
3406 // Conversion to C++: Shell code for return value, native code for arguments | |
3407 TypeSystem::Language lang = argument_index == 0 ? TypeSystem::ShellCode : TypeSystem::NativeCode; | |
3408 if (java_function && writeConversionRule(s, lang, java_function, argument_index, qt_name, java_name)) | |
3409 return; | |
3410 | |
3411 if (java_type == 0) { | |
3412 QString warn = QString("no conversion possible for argument '%1' in function '%2::%3' for " | |
3413 "language '%4'") | |
3414 .arg(argument_index) | |
3415 .arg(java_function->implementingClass()->name()) | |
3416 .arg(java_function->name()) | |
3417 .arg(int(lang)); | |
3418 ReportHandler::warning(warn); | |
3419 return; | |
3420 } | |
3421 | |
3422 | |
3423 Q_ASSERT(java_type->isContainer()); | |
3424 const ContainerTypeEntry *type = | |
3425 static_cast<const ContainerTypeEntry *>(java_type->typeEntry()); | |
3426 | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3427 if (type->type() == ContainerTypeEntry::VectorContainer |
1 | 3428 || type->type() == ContainerTypeEntry::LinkedListContainer |
3429 || type->type() == ContainerTypeEntry::StackContainer | |
3430 || type->type() == ContainerTypeEntry::SetContainer | |
3431 || type->type() == ContainerTypeEntry::QueueContainer) { | |
3432 Q_ASSERT(java_type->instantiations().size() == 1); | |
3433 AbstractMetaType *targ = java_type->instantiations().first(); | |
3434 QString elem_type = getTypeName(targ->typeEntry(), EnumAsInts); | |
3435 elem_type.remove("_ConcreteWrapper"); | |
3436 | |
3437 s << INDENT; | |
3438 writeTypeInfo(s, java_type, ForceValueType); | |
3439 s << qt_name << ";" << endl; | |
3440 | |
3441 { | |
3442 if (type->type() == ContainerTypeEntry::VectorContainer | |
3443 || type->type() == ContainerTypeEntry::StackContainer) | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3444 s << INDENT << qt_name << ".reserve(" << java_name << "->length);" << endl; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3445 |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3446 s << INDENT << "for (int i=0; i<" << java_name << "->length; ++i) {" << endl; |
1 | 3447 { |
3448 Indentation indent(INDENT); | |
3449 if(targ->isTargetLangString()) | |
35 | 3450 s << INDENT << "DArray __d_element;" << endl |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3451 << INDENT << "qtd_get_string_from_array(" << java_name << "->ptr, i, &__d_element);" << endl; |
1 | 3452 else { |
3453 s << INDENT; | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3454 writeTypeInfo(s, targ, Option(VirtualDispatch | ForcePointer | EnumAsInts)); |
1 | 3455 QString cast_string = ""; |
3456 const TypeEntry* centry = targ->typeEntry(); | |
3457 if (centry->isComplex() && (centry->isObject() || centry->isValue() || centry->isInterface())) | |
3458 cast_string = "(void**)"; | |
3459 s << "__d_element;" << endl | |
3460 << INDENT << "qtd_get_" << elem_type << "_from_array(" << java_name << ", i, &__d_element);" << endl; | |
3461 } | |
3462 writeJavaToQt(s, targ, "__qt_element", "__d_element", 0, -1, BoxedPrimitive); | |
3463 QString cont_element = "__qt_element"; | |
3464 if(targ->typeEntry()->isStructInD() && targ->name() != "QModelIndex") | |
3465 cont_element = "__d_element"; | |
3466 s << INDENT << qt_name << " << " << cont_element << ";" << endl; | |
3467 } | |
3468 // qtd s << INDENT << "}" << endl; | |
3469 } | |
3470 s << INDENT << "}" << endl; | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3471 } else if (type->isQList()) { |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3472 writeTypeInfo(s, java_type, ForceValueType); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3473 s << qt_name << " = (*("; |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3474 writeTypeInfo(s, java_type, ForceValueType); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3475 s << "*)" << java_name << ");" << endl; |
1 | 3476 } else if (type->type() == ContainerTypeEntry::PairContainer) { |
3477 QList<AbstractMetaType *> targs = java_type->instantiations(); | |
3478 Q_ASSERT(targs.size() == 2); | |
3479 | |
3480 s << INDENT; | |
3481 writeTypeInfo(s, java_type, ForceValueType); | |
3482 s << " " << qt_name << ";" << endl | |
3483 << INDENT << "if (" << java_name << " != 0) {" << endl; | |
3484 { | |
3485 // separate scope required just in case function takes two QPair's. | |
3486 Indentation indent(INDENT); | |
3487 s << INDENT << "jobject __java_first = qtjambi_pair_get(__jni_env, " | |
3488 << java_name << ", 0);" << endl; | |
3489 writeJavaToQt(s, targs.at(0), "__qt_first", "__java_first", 0, -1, BoxedPrimitive); | |
3490 | |
3491 s << INDENT << "jobject __java_second = qtjambi_pair_get(__jni_env, " | |
3492 << java_name << ", 1);" << endl; | |
3493 writeJavaToQt(s, targs.at(1), "__qt_second", "__java_second", 0, -1, BoxedPrimitive); | |
3494 | |
3495 s << INDENT << qt_name << ".first = __qt_first;" << endl | |
3496 << INDENT << qt_name << ".second = __qt_second;" << endl; | |
3497 } | |
3498 s << INDENT << "}" << endl; | |
3499 } else if (type->type() == ContainerTypeEntry::MapContainer | |
3500 || type->type() == ContainerTypeEntry::HashContainer) { | |
3501 Q_ASSERT(java_type->instantiations().size() == 2); | |
3502 AbstractMetaType *targ_key = java_type->instantiations().at(0); | |
3503 AbstractMetaType *targ_val = java_type->instantiations().at(1); | |
3504 | |
3505 s << INDENT; | |
3506 writeTypeInfo(s, java_type, ForceValueType); | |
3507 s << qt_name << ";" << endl; | |
3508 s << INDENT << "if (" << java_name << " != 0) {" << endl; | |
3509 { | |
3510 Indentation indent(INDENT); | |
3511 s << INDENT << "int __qt_list_size = qtjambi_map_size(__jni_env, " << java_name | |
3512 << ");" << endl | |
3513 << INDENT | |
3514 << "jobjectArray __java_entry_set = qtjambi_map_entryset_array(__jni_env, " << java_name | |
3515 << ");" << endl; | |
3516 | |
3517 s << INDENT << "for (int i=0; i<__qt_list_size; ++i) {" << endl; | |
3518 { | |
3519 Indentation indent(INDENT); | |
3520 s << INDENT | |
3521 << "QPair<jobject, jobject> __java_entry = " | |
3522 << "qtjambi_entryset_array_get(__jni_env, __java_entry_set, i);" | |
3523 << endl | |
3524 << INDENT << "jobject __java_key = __java_entry.first;" << endl | |
3525 << INDENT << "jobject __java_val = __java_entry.second;" << endl; | |
3526 writeJavaToQt(s, targ_key, "__qt_key", "__java_key", 0, -1, BoxedPrimitive); | |
3527 writeJavaToQt(s, targ_val, "__qt_val", "__java_val", 0, -1, BoxedPrimitive); | |
3528 s << INDENT << qt_name << ".insert(__qt_key, __qt_val);" << endl; | |
3529 } | |
3530 s << INDENT << "}" << endl; | |
3531 } | |
3532 s << INDENT << "}" << endl; | |
3533 | |
3534 } else { | |
3535 ReportHandler::warning(QString("unable to generate container type %1, %2") | |
3536 .arg(java_type->name()).arg(type->type())); | |
3537 } | |
3538 | |
3539 } | |
3540 | |
3541 | |
3542 void CppImplGenerator::writeFunctionCall(QTextStream &s, const QString &object_name, | |
3543 const AbstractMetaFunction *java_function, | |
3544 const QString &prefix, | |
3545 Option option, | |
3546 const QStringList &extra_arguments) | |
3547 { | |
3548 QString function_name = option & OriginalName ? java_function->originalName() : java_function->name(); | |
3549 | |
3550 AbstractMetaClassList interfaces = java_function->implementingClass()->interfaces(); | |
3551 | |
3552 QString classPrefix; | |
3553 if (prefix.isEmpty() | |
3554 && !java_function->implementingClass()->interfaces().isEmpty() | |
3555 && !java_function->implementingClass()->inheritsFrom(java_function->declaringClass())) { | |
3556 classPrefix = java_function->declaringClass()->qualifiedCppName() + "::"; | |
3557 } | |
3558 | |
3559 if (java_function->isInGlobalScope()) { | |
3560 | |
3561 // Global scope stream operators need the arguments to be reordered (this ref at end) | |
3562 // so we special case them in order to simplify this code | |
3563 bool stream_operator = java_function->originalName() == "operator<<" | |
3564 || java_function->originalName() == "operator>>"; | |
3565 | |
3566 if (java_function->type() == 0) | |
3567 s << "if (" << object_name << " != 0) "; | |
3568 else | |
3569 s << "(" << object_name << " != 0) ? "; | |
3570 s << "::" << prefix << function_name << "("; | |
3571 if (!stream_operator) | |
3572 s << "*" << object_name << ", "; | |
3573 writeFunctionCallArguments(s, java_function, "__qt_"); | |
3574 if (stream_operator) | |
3575 s << ", *" << object_name; | |
3576 s << ")"; | |
3577 if (java_function->type() != 0) | |
3578 s << " : " << default_return_statement_qt(java_function->type(), Generator::Option(option | Generator::NoReturnStatement)); | |
3579 s << ";"; | |
3580 } else { | |
3581 s << object_name << (java_function->isStatic() ? QLatin1String("::") : QLatin1String("->") + classPrefix) | |
3582 << prefix << function_name << "("; | |
3583 writeFunctionCallArguments(s, java_function, "__qt_"); | |
3584 | |
3585 // The extra arguments... | |
3586 for (int i=0; i<extra_arguments.size(); ++i) { | |
3587 if (i > 0 || java_function->arguments().size() != 0) | |
3588 s << ", "; | |
3589 s << extra_arguments.at(i); | |
3590 } | |
3591 | |
3592 s << ");"; | |
3593 } | |
3594 | |
3595 s << endl; | |
3596 | |
3597 } | |
3598 | |
3599 | |
3600 void CppImplGenerator::writeFunctionCallArguments(QTextStream &s, | |
3601 const AbstractMetaFunction *java_function, | |
3602 const QString &prefix, | |
3603 Option options) | |
3604 { | |
3605 AbstractMetaArgumentList arguments = java_function->arguments(); | |
3606 | |
3607 int written_arguments = 0; | |
3608 const AbstractMetaClass *cls = java_function->ownerClass(); | |
3609 if (java_function->isConstructor() && cls->hasVirtualFunctions()) { | |
3610 s << "d_ptr"; | |
3611 written_arguments++; | |
3612 } | |
3613 for (int i=0; i<arguments.size(); ++i) { | |
3614 const AbstractMetaArgument *argument = arguments.at(i); | |
3615 AbstractMetaType *a_type = argument->type(); | |
3616 | |
3617 if ((options & SkipRemovedArguments) == SkipRemovedArguments | |
3618 && java_function->argumentRemoved(i+1)) { | |
3619 continue; | |
3620 } | |
3621 | |
3622 if (written_arguments++ > 0) { | |
3623 s << ", "; | |
3624 } | |
3625 | |
3626 bool enum_as_int = (options & EnumAsInts) && (argument->type()->typeEntry()->isEnum() | |
3627 || argument->type()->typeEntry()->isFlags()); | |
3628 if (a_type->isEnum()) { | |
3629 AbstractMetaEnum *java_enum = | |
3630 m_classes.findEnum(static_cast<const EnumTypeEntry *>(argument->type()->typeEntry())); | |
3631 if (java_enum == 0) { | |
3632 ReportHandler::warning(QString("enum not found: '%1'") | |
3633 .arg(argument->type()->typeEntry()->qualifiedCppName())); | |
3634 } else { | |
3635 enum_as_int |= !java_enum->isPublic(); | |
3636 } | |
3637 } | |
3638 | |
3639 if ( (options & VirtualDispatch) | |
3640 && a_type->isContainer()) { | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3641 if ( ((const ContainerTypeEntry *)a_type->typeEntry())->isQList() ) |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3642 s << "(void*)&" << argument->indexedName(); |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3643 else |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
294
diff
changeset
|
3644 s << "__d_" << argument->indexedName(); |
1 | 3645 continue; |
3646 } | |
3647 | |
3648 if ((!(options & NoCasts) && !enum_as_int) || ((options & ForceEnumCast) && a_type->isEnum())) { | |
3649 | |
3650 // If the type in the signature is specified without template instantiation, but the | |
3651 // class is actually a template class, then we have troubles. | |
3652 AbstractMetaClass *cls = classes().findClass(argument->type()->typeEntry()->qualifiedCppName()); | |
3653 | |
3654 if ( (options & VirtualDispatch) && !a_type->typeEntry()->isStructInD() | |
3655 && ( a_type->isValue() | |
3656 || (a_type->isReference() && (a_type->typeEntry()->isValue() || a_type->typeEntry()->isObject() || a_type->typeEntry()->isPrimitive()) && !a_type->isTargetLangString()) | |
3657 ) ) | |
3658 s << "&"; | |
3659 | |
3660 if( (options & VirtualDispatch) && a_type->typeEntry()->isStructInD() && a_type->isReference()) | |
3661 s << "&"; | |
3662 | |
3663 if ( (options & VirtualDispatch) | |
3664 && ( a_type->isTargetLangString() || a_type->name() == "QModelIndex" ) ) | |
3665 ; | |
3666 else if (cls == 0 || cls->templateArguments().size() == a_type->instantiations().size()) { | |
3667 s << "("; | |
3668 writeTypeInfo(s, a_type, options); | |
3669 s << ")"; | |
3670 } | |
3671 } | |
3672 | |
3673 if (a_type->isNativePointer() && a_type->typeEntry()->name() == "QString" && !a_type->isReference()) | |
3674 s << "&"; | |
3675 | |
3676 if ( ( !a_type->isPrimitive() | |
3677 || !java_function->conversionRule(TypeSystem::NativeCode, argument->argumentIndex()+1).isEmpty() ) | |
3678 && (!a_type->typeEntry()->isStructInD() || a_type->name() == "QModelIndex") ) { | |
3679 s << prefix; | |
3680 } | |
3681 | |
3682 if (options & VirtualDispatch) { | |
3683 if( argument->type()->isTargetLangString()) | |
3684 s << argument->indexedName() << ".utf16(), " << argument->indexedName() << ".size()"; | |
3685 else if (argument->type()->name() == "QModelIndex") | |
3686 s << "qtd_from_QModelIndex(" << argument->indexedName() << ")"; | |
3687 else | |
3688 s << argument->indexedName(); | |
3689 } else | |
3690 s << argument->indexedName(); | |
3691 } | |
3692 } | |
3693 | |
3694 | |
3695 QString CppImplGenerator::translateType(const AbstractMetaType *java_type, Option option, bool d_export) | |
3696 { | |
3697 if (!java_type) | |
3698 return "void"; | |
3699 | |
3700 const TypeEntry *type = java_type->typeEntry(); | |
3701 QString class_name = type->name(); | |
3702 QString qualified_class_name = fixCppTypeName(type->qualifiedCppName()); | |
3703 QString d_name = qualified_class_name; | |
3704 if (d_export) | |
3705 d_name = type->lookupName(); | |
3706 | |
3707 if (java_type->isPrimitive() | |
3708 || java_type->isTargetLangString() | |
3709 || java_type->isVariant() | |
3710 || java_type->isJObjectWrapper() | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3711 || java_type->isTargetLangChar()) { |
1 | 3712 return d_name; |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3713 } else if (java_type->isArray()) { |
39 | 3714 if (d_export) |
3715 return java_type->arrayElementType()->name() + "*"; | |
3716 else | |
3717 return java_type->arrayElementType()->typeEntry()->qualifiedCppName() + "*"; | |
1 | 3718 } else if (java_type->isIntegerEnum() || java_type->isIntegerFlags() |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3719 || ((option & EnumAsInts) && (java_type->isEnum() || java_type->isFlags()))) { |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3720 return "int"; |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3721 } else if (java_type->isReference()) { |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3722 if (java_type->typeEntry()->isValue()) |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3723 return "void*"; |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3724 else |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3725 return d_name + " "+ QString(java_type->actualIndirections(), '*'); |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3726 } else if (java_type->isNativePointer()) { |
190 | 3727 if (java_type->typeEntry()->isStructInD() && dVersion == 2 && java_type->isConstant() && d_export) |
3728 return "const(" + d_name + QString(java_type->indirections()-1, '*') + ")*"; | |
3729 else if (java_type->typeEntry()->isValue()) | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3730 return "void*"; |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3731 else if (java_type->typeEntry()->isEnum() && d_export) |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3732 return "int" + QString(java_type->indirections(), '*'); |
188 | 3733 else { |
3734 if (java_type->isConstant() && dVersion == 2 && d_export) | |
190 | 3735 return "const (" + d_name + QString(java_type->indirections(), '*') + ")"; |
188 | 3736 else |
3737 return d_name + QString(java_type->indirections(), '*'); | |
3738 } | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3739 } else { |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3740 return d_name + QString(java_type->indirections(), '*'); |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
21
diff
changeset
|
3741 } |
81 | 3742 } |
1 | 3743 |
3744 void CppImplGenerator::writeExtraIncludes(QTextStream &s, const AbstractMetaClass *java_class) | |
3745 { | |
3746 IncludeList includes = java_class->typeEntry()->extraIncludes(); | |
3747 qSort(includes.begin(), includes.end()); | |
3748 | |
3749 int used = 0; | |
3750 foreach (const Include &i, includes) { | |
3751 if (i.type != Include::TargetLangImport) { | |
3752 s << i.toString() << endl; | |
3753 ++used; | |
3754 } | |
3755 } | |
3756 | |
3757 | |
3758 if (used) | |
3759 s << endl; | |
3760 | |
3761 } | |
3762 | |
3763 | |
3764 void CppImplGenerator::writeDefaultConstructedValues_helper(QSet<QString> &values, | |
3765 const AbstractMetaFunction *func) | |
3766 { | |
3767 foreach (AbstractMetaArgument *arg, func->arguments()) { | |
3768 AbstractMetaType *type = arg->type(); | |
3769 if (func->typeReplaced(arg->argumentIndex()+1).isEmpty() && type->isValue() && hasDefaultConstructor(type)) | |
3770 values << type->typeEntry()->qualifiedCppName(); | |
3771 } | |
3772 } | |
3773 | |
3774 | |
3775 void CppImplGenerator::writeDefaultConstructedValues(QTextStream &s, const AbstractMetaClass *java_class) { | |
3776 | |
3777 QSet<QString> values; | |
3778 | |
3779 // Class functions, more or less copied from the logic in write(Class) above... | |
3780 AbstractMetaFunctionList class_funcs; | |
3781 | |
3782 // Add normal final functions | |
3783 foreach (AbstractMetaFunction *function, java_class->functionsInTargetLang()) { | |
3784 if (!function->isEmptyFunction()) | |
3785 class_funcs << function; | |
3786 } | |
3787 | |
3788 // Add abstract functions, I think... | |
3789 foreach (AbstractMetaFunction *function, java_class->queryFunctions(AbstractMetaClass::NormalFunctions | |
3790 | AbstractMetaClass::AbstractFunctions | |
3791 | AbstractMetaClass::NotRemovedFromTargetLang)) { | |
3792 if (function->implementingClass() != java_class) | |
3793 class_funcs << function; | |
3794 } | |
3795 | |
3796 // Signals (their c++ wrapper calls actually...) | |
3797 class_funcs += java_class->queryFunctions(AbstractMetaClass::Signals); | |
3798 | |
3799 // | |
3800 foreach (AbstractMetaFunction *f, class_funcs) { | |
3801 writeDefaultConstructedValues_helper(values, f); | |
3802 } | |
3803 | |
3804 foreach (AbstractMetaField *field, java_class->fields()) { | |
3805 writeDefaultConstructedValues_helper(values, field->setter()); | |
3806 } | |
3807 | |
3808 if (!values.isEmpty()) { | |
3809 s << endl << endl | |
3810 << "// Default constructed values used throughout final functions..." << endl; | |
3811 for (QSet<QString>::const_iterator it = values.constBegin(); it != values.constEnd(); ++it) { | |
3812 s << "Q_GLOBAL_STATIC(" << *it << ", default_" << QString(*it).replace("::", "_") | |
3813 << ");" << endl; | |
3814 } | |
3815 s << endl << endl; | |
3816 } | |
3817 } |