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