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