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