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