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