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