Mercurial > projects > qtd
annotate generator/dgenerator.cpp @ 130:7ae9bc9d6935
reference counting for return values. applied to QMenu
author | eldar |
---|---|
date | Sun, 07 Jun 2009 11:42:29 +0000 |
parents | e416c5215366 |
children | 4d1c5d1d1bbf |
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 "dgenerator.h" | |
43 #include "reporthandler.h" | |
44 #include "docparser.h" | |
45 #include "jumptable.h" | |
46 #include "cppimplgenerator.h" | |
47 #include "fileout.h" | |
48 | |
49 #include <QtCore/QDir> | |
50 #include <QtCore/QTextStream> | |
51 #include <QtCore/QVariant> | |
52 #include <QtCore/QRegExp> | |
53 #include <QDebug> | |
54 | |
55 #include <iostream> | |
56 | |
57 | |
58 static Indentor INDENT; | |
59 | |
60 DGenerator::DGenerator() | |
61 : m_doc_parser(0), | |
62 m_docs_enabled(false), | |
63 m_native_jump_table(false), | |
64 m_recursive(0), | |
65 m_isRecursive(false) | |
66 { | |
67 excludedTypes << "long long" << "bool" << "int" << "QString" << "char" << "WId" | |
68 << "unsigned char" << "uint" << "double" << "short" << "float" | |
69 << "signed char" << "unsigned short" << "QBool" << "unsigned int" | |
70 << "Qt::HANDLE" << "QChar" << "java.lang.JObjectWrapper" << "void" | |
71 << "QLatin1String" << "unsigned long long" << "signed int" | |
72 << "signed short" << "Array" << "GLuint" << "GLenum" << "GLint" | |
73 << "unsigned long" << "ulong" << "long" << "QByteRef" | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
74 << "QStringList" << "QList" << "QVector" << "QPair" |
39 | 75 << "QSet" << "QStringRef" << "quintptr"; |
1 | 76 } |
77 | |
78 QString DGenerator::fileNameForClass(const AbstractMetaClass *d_class) const | |
79 { | |
80 return QString("%1.d").arg(d_class->name()); | |
81 } | |
82 | |
83 void DGenerator::writeFieldAccessors(QTextStream &s, const AbstractMetaField *field) | |
84 { | |
85 Q_ASSERT(field->isPublic() || field->isProtected()); | |
86 | |
87 const AbstractMetaClass *declaringClass = field->enclosingClass(); | |
88 | |
89 FieldModification mod = declaringClass->typeEntry()->fieldModification(field->name()); | |
90 | |
91 // Set function | |
92 if (mod.isWritable() && !field->type()->isConstant()) { | |
93 const AbstractMetaFunction *setter = field->setter(); | |
94 if (declaringClass->hasFunction(setter)) { | |
95 QString warning = | |
96 QString("class '%1' already has setter '%2' for public field '%3'") | |
97 .arg(declaringClass->name()).arg(setter->name()).arg(field->name()); | |
98 ReportHandler::warning(warning); | |
99 } else { | |
100 if (!notWrappedYet(setter)) // qtd2 | |
101 writeFunction(s, setter); | |
102 } | |
103 } | |
104 | |
105 // Get function | |
106 const AbstractMetaFunction *getter = field->getter(); | |
107 if (mod.isReadable()) { | |
108 if (declaringClass->hasFunction(getter)) { | |
109 QString warning = | |
110 QString("class '%1' already has getter '%2' for public field '%3'") | |
111 .arg(declaringClass->name()).arg(getter->name()).arg(field->name()); | |
112 ReportHandler::warning(warning); | |
113 } else { | |
114 if (!notWrappedYet(getter)) // qtd2 | |
115 writeFunction(s, getter); | |
116 } | |
117 } | |
118 } | |
119 | |
120 QString DGenerator::translateType(const AbstractMetaType *d_type, const AbstractMetaClass *context, Option option) | |
121 { | |
122 QString s; | |
123 | |
124 if (context != 0 && d_type != 0 && context->typeEntry()->isGenericClass() && d_type->originalTemplateType() != 0) | |
125 d_type = d_type->originalTemplateType(); | |
126 | |
127 if (!d_type) { | |
128 s = "void"; | |
81 | 129 } else if (d_type->typeEntry()->qualifiedCppName() == "QChar") { |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
130 s = "wchar" + QString(d_type->actualIndirections(), '*'); |
81 | 131 } else if (d_type->typeEntry() && d_type->typeEntry()->qualifiedCppName() == "QString") { |
1 | 132 s = "string"; |
133 } else if (d_type->isArray()) { | |
134 s = translateType(d_type->arrayElementType(), context) + "[]"; | |
135 } else if (d_type->isEnum() /* qtd2 || d_type->isFlags() */) { | |
136 if (( d_type->isEnum() && ((EnumTypeEntry *)d_type->typeEntry())->forceInteger() ) | |
137 || ( d_type->isFlags() && ((FlagsTypeEntry *)d_type->typeEntry())->forceInteger() ) ) { | |
138 if (option & BoxedPrimitive) | |
139 s = "java.lang.Integer"; | |
140 else | |
141 s = "int"; | |
142 } else { | |
143 if (option & EnumAsInts) | |
144 s = "int"; | |
145 else | |
146 s = d_type->typeEntry()->qualifiedTargetLangName(); | |
147 } | |
148 } else if (d_type->isFlags()) { // qtd2 begin | |
149 if (d_type->isFlags() && ((FlagsTypeEntry *)d_type->typeEntry())->forceInteger()) { | |
150 if (option & BoxedPrimitive) | |
151 s = "java.lang.Integer"; | |
152 else | |
153 s = "int"; | |
154 } else | |
155 s = "int"; | |
156 } else { | |
157 /* qtd if (d_type->isPrimitive() && (option & BoxedPrimitive)) { | |
158 s = static_cast<const PrimitiveTypeEntry *>(d_type->typeEntry())->javaObjectName(); | |
159 } else */ if (d_type->isVariant()) { | |
160 s = "QVariant"; | |
161 } else if (d_type->isNativePointer()) { | |
162 if (d_type->typeEntry()->isValue() && !d_type->typeEntry()->isStructInD()) | |
163 s = d_type->typeEntry()->lookupName(); | |
164 else if (d_type->typeEntry()->isEnum()) | |
165 s = "int" + QString(d_type->actualIndirections(), '*'); | |
166 else | |
167 s = d_type->typeEntry()->lookupName() + QString(d_type->actualIndirections(), '*'); | |
168 } else if (d_type->isContainer()) { | |
169 const ContainerTypeEntry* c_entry = static_cast<const ContainerTypeEntry*>(d_type->typeEntry()); | |
170 Q_ASSERT(c_entry); | |
171 | |
172 if ((option & SkipTemplateParameters) == 0) { | |
173 QList<AbstractMetaType *> args = d_type->instantiations(); | |
174 | |
175 if (args.size() == 1) // QVector or QList | |
176 s = translateType(args.at(0), context, BoxedPrimitive) + "[]"; | |
177 else if(args.size() == 2) { // all sorts of maps | |
178 s = translateType(args.at(1), context, BoxedPrimitive); // value | |
179 bool isMultiMap = static_cast<const ContainerTypeEntry *>(d_type->typeEntry())->type() == ContainerTypeEntry::MultiMapContainer; | |
180 if (isMultiMap) | |
181 s += "[]"; | |
182 s += "[" + translateType(args.at(0), context, BoxedPrimitive) + "]"; | |
183 } else { | |
184 s = d_type->typeEntry()->qualifiedTargetLangName(); | |
185 | |
186 for (int i=0; i<args.size(); ++i) { | |
187 if (i != 0) | |
188 s += ", "; | |
189 bool isMultiMap = static_cast<const ContainerTypeEntry *>(d_type->typeEntry())->type() == ContainerTypeEntry::MultiMapContainer | |
190 && i == 1; | |
191 if (isMultiMap) | |
192 s += "java.util.List<"; | |
193 s += translateType(args.at(i), context, BoxedPrimitive); | |
194 if (isMultiMap) | |
195 s += ">"; | |
196 } | |
197 s += '>'; | |
198 } | |
199 } | |
200 | |
201 } else { | |
202 const TypeEntry *type = d_type->typeEntry(); | |
203 if (type->designatedInterface()) | |
204 type = type->designatedInterface(); | |
205 if (type->isString()) | |
206 s = "string"; | |
207 else if (type->isObject()){ | |
208 s = type->name(); | |
209 } else { | |
210 s = type->lookupName(); | |
211 } | |
212 } | |
213 } | |
214 | |
215 return s; | |
216 } | |
217 | |
218 QString DGenerator::argumentString(const AbstractMetaFunction *d_function, | |
219 const AbstractMetaArgument *d_argument, | |
220 uint options) | |
221 { | |
222 QString modified_type = d_function->typeReplaced(d_argument->argumentIndex() + 1); | |
223 QString arg; | |
224 | |
225 AbstractMetaType *type = d_argument->type(); | |
226 // if argument is "QString &" ref attribute needed | |
227 if (type->typeEntry()->isValue() && type->isNativePointer() && type->typeEntry()->name() == "QString") | |
228 arg = "ref "; | |
229 | |
230 if (modified_type.isEmpty()) | |
231 arg += translateType(d_argument->type(), d_function->implementingClass(), (Option) options); | |
232 else | |
233 arg += modified_type.replace('$', '.'); | |
234 | |
235 if ((options & SkipName) == 0) { | |
236 arg += " "; | |
237 arg += d_argument->argumentName(); | |
238 } | |
239 | |
240 if (!d_argument->defaultValueExpression().isEmpty()) // qtd | |
241 arg += " = " + d_argument->defaultValueExpression(); | |
242 | |
243 return arg; | |
244 } | |
245 | |
246 void DGenerator::writeArgument(QTextStream &s, | |
247 const AbstractMetaFunction *d_function, | |
248 const AbstractMetaArgument *d_argument, | |
249 uint options) | |
250 { | |
251 s << argumentString(d_function, d_argument, options); | |
252 } | |
253 | |
254 | |
255 void DGenerator::writeIntegerEnum(QTextStream &s, const AbstractMetaEnum *d_enum) | |
256 { | |
257 const AbstractMetaEnumValueList &values = d_enum->values(); | |
258 | |
259 s << " public static class " << d_enum->name() << "{" << endl; | |
260 for (int i=0; i<values.size(); ++i) { | |
261 AbstractMetaEnumValue *value = values.at(i); | |
262 | |
263 if (d_enum->typeEntry()->isEnumValueRejected(value->name())) | |
264 continue; | |
265 | |
266 if (m_doc_parser) | |
267 s << m_doc_parser->documentation(value); | |
268 | |
269 s << " public static final int " << value->name() << " = " << value->value(); | |
270 s << ";"; | |
271 s << endl; | |
272 } | |
273 | |
274 s << " } // end of enum " << d_enum->name() << endl << endl; | |
275 } | |
276 | |
277 void DGenerator::writeEnumAlias(QTextStream &s, const AbstractMetaEnum *d_enum) | |
278 { | |
279 // aliases for enums to be used in easier way like QFont.Bold instead of QFont.Weight.Bold | |
280 s << QString(" alias %1 %2;").arg(d_enum->typeEntry()->qualifiedTargetLangName()).arg(d_enum->name()) << endl << endl; | |
281 const AbstractMetaEnumValueList &values = d_enum->values(); | |
282 for (int i=0; i<values.size(); ++i) { | |
283 AbstractMetaEnumValue *enum_value = values.at(i); | |
284 | |
285 if (d_enum->typeEntry()->isEnumValueRejected(enum_value->name())) | |
286 continue; | |
287 | |
288 s << QString(" alias %1.%2 %2;").arg(d_enum->typeEntry()->qualifiedTargetLangName()).arg(enum_value->name()) << endl; | |
289 } | |
290 s << endl; | |
291 } | |
292 | |
293 void DGenerator::writeEnum(QTextStream &s, const AbstractMetaEnum *d_enum) | |
294 { | |
295 if (m_doc_parser) { | |
296 s << m_doc_parser->documentation(d_enum); | |
297 } | |
298 | |
299 /* qtd | |
300 | |
301 if (d_enum->typeEntry()->forceInteger()) { | |
302 writeIntegerEnum(s, d_enum); | |
303 return; | |
304 } | |
305 | |
306 // Check if enums in QObjects are declared in the meta object. If not | |
307 if ( (d_enum->enclosingClass()->isQObject() || d_enum->enclosingClass()->isQtNamespace()) | |
308 && !d_enum->hasQEnumsDeclaration()) { | |
309 s << " @QtBlockedEnum" << endl; | |
310 } | |
311 */ | |
312 // Generates Java 1.5 type enums | |
313 s << " public enum " << d_enum->enclosingClass()->name() << "_" << d_enum->name() << " {" << endl; | |
314 const AbstractMetaEnumValueList &values = d_enum->values(); | |
315 EnumTypeEntry *entry = d_enum->typeEntry(); | |
316 | |
317 for (int i=0; i<values.size(); ++i) { | |
318 AbstractMetaEnumValue *enum_value = values.at(i); | |
319 | |
320 if (d_enum->typeEntry()->isEnumValueRejected(enum_value->name())) | |
321 continue; | |
322 | |
323 if (m_doc_parser) | |
324 s << m_doc_parser->documentation(enum_value); | |
325 | |
326 s << " " << enum_value->name() << " = " << enum_value->value(); | |
327 | |
328 if (i != values.size() - 1) { | |
329 AbstractMetaEnumValue *next_value = values.at(i+1); // qtd | |
330 if (!(d_enum->typeEntry()->isEnumValueRejected(next_value->name()) && i == values.size() - 2)) // qtd | |
331 s << "," << endl; | |
332 } | |
333 } | |
334 /* qtd | |
335 if (entry->isExtensible()) | |
336 s << " CustomEnum = 0"; | |
337 */ | |
338 s << endl << INDENT << "}" << endl << endl; // qtd | |
339 | |
340 | |
341 /* qtd s << ";" << endl << endl; | |
342 | |
343 s << " " << d_enum->name() << "(int value) { this.value = value; }" << endl | |
344 << " public int value() { return value; }" << endl | |
345 << endl; | |
346 | |
347 // Write out the createQFlags() function if its a QFlags enum | |
348 if (entry->flags()) { | |
349 FlagsTypeEntry *flags_entry = entry->flags(); | |
350 s << " public static " << flags_entry->targetLangName() << " createQFlags(" | |
351 << entry->targetLangName() << " ... values) {" << endl | |
352 << " return new " << flags_entry->targetLangName() << "(values);" << endl | |
353 << " }" << endl; | |
354 } | |
355 | |
356 // The resolve functions. The public one that returns the right | |
357 // type and an internal one that has a generic signature. Makes it | |
358 // easier to find the right one from JNI. | |
359 s << " public static " << d_enum->name() << " resolve(int value) {" << endl | |
360 << " return (" << d_enum->name() << ") resolve_internal(value);" << endl | |
361 << " }" << endl | |
362 << " private static Object resolve_internal(int value) {" << endl | |
363 << " switch (value) {" << endl; | |
364 | |
365 for (int i=0; i<values.size(); ++i) { | |
366 AbstractMetaEnumValue *e = values.at(i); | |
367 | |
368 if (d_enum->typeEntry()->isEnumValueRejected(e->name())) | |
369 continue; | |
370 | |
371 s << " case " << e->value() << ": return " << e->name() << ";" << endl; | |
372 } | |
373 | |
374 s << " }" << endl; | |
375 | |
376 if (entry->isExtensible()) { | |
377 s << " if (enumCache == null)" << endl | |
378 << " enumCache = new java.util.HashMap<Integer, " << d_enum->name() | |
379 << ">();" << endl | |
380 << " " << d_enum->name() << " e = enumCache.get(value);" << endl | |
381 << " if (e == null) {" << endl | |
382 << " e = (" << d_enum->name() << ") qt.GeneratorUtilities.createExtendedEnum(" | |
383 << "value, CustomEnum.ordinal(), " << d_enum->name() << ".class, CustomEnum.name());" | |
384 << endl | |
385 << " enumCache.put(value, e);" << endl | |
386 << " }" << endl | |
387 << " return e;" << endl; | |
388 } else { | |
389 s << " throw new qt.QNoSuchEnumValueException(value);" << endl; | |
390 } | |
391 | |
392 | |
393 s << " }" << endl; | |
394 | |
395 s << " private final int value;" << endl | |
396 << endl; | |
397 if (entry->isExtensible()) { | |
398 s << " private static java.util.HashMap<Integer, " << d_enum->name() | |
399 << "> enumCache;"; | |
400 } | |
401 s << " }" << endl; | |
402 */ | |
403 // Write out the QFlags if present... | |
404 /* FlagsTypeEntry *flags_entry = entry->flags(); | |
405 if (flags_entry) { | |
406 QString flagsName = flags_entry->targetLangName(); | |
407 s << INDENT << "alias QFlags!(" << d_enum->name() << ") " << flagsName << ";" << endl << endl; | |
408 }*/ | |
409 } | |
410 | |
411 void DGenerator::writePrivateNativeFunction(QTextStream &s, const AbstractMetaFunction *d_function) | |
412 { | |
413 int exclude_attributes = AbstractMetaAttributes::Public | AbstractMetaAttributes::Protected; | |
414 int include_attributes = 0; | |
415 | |
416 if (d_function->isEmptyFunction()) | |
417 exclude_attributes |= AbstractMetaAttributes::Native; | |
418 else | |
419 include_attributes |= AbstractMetaAttributes::Native; | |
420 | |
421 // if (!d_function->isConstructor()) | |
422 // include_attributes |= AbstractMetaAttributes::Static; | |
423 | |
424 writeFunctionAttributes(s, d_function, include_attributes, exclude_attributes, | |
425 EnumAsInts | ExternC | |
426 | (d_function->isEmptyFunction() | |
427 || d_function->isNormal() | |
428 || d_function->isSignal() ? 0 : SkipReturnType)); | |
429 | |
430 if (d_function->isConstructor()) | |
431 s << "void* "; | |
432 | |
433 | |
434 s << d_function->marshalledName(); | |
435 /* qtd | |
436 s << "("; | |
437 | |
438 AbstractMetaArgumentList arguments = d_function->arguments(); | |
439 | |
440 if (!d_function->isStatic() && !d_function->isConstructor()) | |
441 s << "void *__this__nativeId"; | |
442 for (int i=0; i<arguments.count(); ++i) { | |
443 const AbstractMetaArgument *arg = arguments.at(i); | |
444 | |
445 if (!d_function->argumentRemoved(i+1)) { | |
446 if (i > 0 || (!d_function->isStatic() && !d_function->isConstructor())) | |
447 s << ", "; | |
448 | |
449 if (!arg->type()->hasNativeId()) | |
450 writeArgument(s, d_function, arg, EnumAsInts); | |
451 else | |
452 s << "void *" << arg->argumentName(); | |
453 } | |
454 } | |
455 s << ")"; | |
456 */ | |
457 | |
458 CppImplGenerator::writeFinalFunctionArguments(s, d_function, true); // qtd | |
459 | |
460 // Make sure people don't call the private functions | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
461 // qtd remember name QNoImplementationException |
1 | 462 if (d_function->isEmptyFunction()) { |
463 s << endl | |
464 << INDENT << "{" << endl | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
465 << INDENT << " throw new Exception(\"No Implementation Exception\");" << endl |
1 | 466 << INDENT << "}" << endl << endl; |
467 } else { | |
468 s << ";" << endl; | |
469 } | |
470 } | |
471 | |
472 static QString function_call_for_ownership(TypeSystem::Ownership owner) | |
473 { | |
474 if (owner == TypeSystem::CppOwnership) { | |
475 return "__set_native_ownership(true)"; | |
476 } else /* qtd 2 if (owner == TypeSystem::TargetLangOwnership) */ { | |
477 return "__set_native_ownership(false)"; | |
478 }/* else if (owner == TypeSystem::DefaultOwnership) { | |
479 return "__no_real_delete = false"; | |
480 | |
481 } else { | |
482 Q_ASSERT(false); | |
483 return "bogus()"; | |
484 }*/ | |
485 } | |
486 | |
487 void DGenerator::writeOwnershipForContainer(QTextStream &s, TypeSystem::Ownership owner, | |
488 AbstractMetaType *type, const QString &arg_name) | |
489 { | |
490 Q_ASSERT(type->isContainer()); | |
491 | |
492 s << INDENT << "for (" << type->instantiations().at(0)->fullName() << " i : " | |
493 << arg_name << ")" << endl | |
494 << INDENT << " if (i != null) i." << function_call_for_ownership(owner) << ";" << endl; | |
495 | |
496 } | |
497 | |
498 void DGenerator::writeOwnershipForContainer(QTextStream &s, TypeSystem::Ownership owner, | |
499 AbstractMetaArgument *arg) | |
500 { | |
501 writeOwnershipForContainer(s, owner, arg->type(), arg->argumentName()); | |
502 } | |
503 | |
504 static FunctionModificationList get_function_modifications_for_class_hierarchy(const AbstractMetaFunction *d_function) | |
505 { | |
506 FunctionModificationList mods; | |
507 const AbstractMetaClass *cls = d_function->implementingClass(); | |
508 while (cls != 0) { | |
509 mods += d_function->modifications(cls); | |
510 | |
511 if (cls == cls->baseClass()) | |
512 break; | |
513 cls = cls->baseClass(); | |
514 } | |
515 return mods; | |
516 } | |
517 | |
518 void DGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaFunction *d_function, | |
519 CodeSnip::Position position) | |
520 { | |
521 FunctionModificationList mods = get_function_modifications_for_class_hierarchy(d_function); | |
522 foreach (FunctionModification mod, mods) { | |
523 if (mod.snips.count() <= 0) | |
524 continue ; | |
525 | |
526 foreach (CodeSnip snip, mod.snips) { | |
527 if (snip.position != position) | |
528 continue ; | |
529 | |
530 if (snip.language != TypeSystem::TargetLangCode) | |
531 continue ; | |
532 | |
533 QString code; | |
534 QTextStream tmpStream(&code); | |
535 snip.formattedCode(tmpStream, INDENT); | |
536 ArgumentMap map = snip.argumentMap; | |
537 ArgumentMap::iterator it = map.begin(); | |
538 for (;it!=map.end();++it) { | |
539 int pos = it.key() - 1; | |
540 QString meta_name = it.value(); | |
541 | |
542 if (pos >= 0 && pos < d_function->arguments().count()) { | |
543 code = code.replace(meta_name, d_function->arguments().at(pos)->argumentName()); | |
544 } else { | |
545 QString debug = QString("argument map specifies invalid argument index %1" | |
546 "for function '%2'") | |
547 .arg(pos + 1).arg(d_function->name()); | |
548 ReportHandler::warning(debug); | |
549 } | |
550 | |
551 } | |
552 s << code << endl; | |
553 } | |
554 } | |
555 } | |
556 | |
557 | |
558 void DGenerator::writeJavaCallThroughContents(QTextStream &s, const AbstractMetaFunction *d_function, uint attributes) | |
559 { | |
560 Q_UNUSED(attributes); | |
561 writeInjectedCode(s, d_function, CodeSnip::Beginning); | |
562 /* qtd | |
563 if (d_function->implementingClass()->isQObject() | |
564 && !d_function->isStatic() | |
565 && !d_function->isConstructor() | |
566 && d_function->name() != QLatin1String("thread") | |
567 && d_function->name() != QLatin1String("disposeLater")) { | |
568 s << INDENT << "qt.GeneratorUtilities.threadCheck(this);" << endl; | |
569 } | |
570 */ | |
571 AbstractMetaArgumentList arguments = d_function->arguments(); | |
572 | |
573 if (!d_function->isConstructor()) { | |
574 TypeSystem::Ownership owner = d_function->ownership(d_function->implementingClass(), TypeSystem::TargetLangCode, -1); | |
575 if (owner != TypeSystem::InvalidOwnership) | |
576 s << INDENT << "this." << function_call_for_ownership(owner) << ";" << endl; | |
577 } | |
578 | |
579 for (int i=0; i<arguments.count(); ++i) { | |
580 AbstractMetaArgument *arg = arguments.at(i); | |
581 | |
582 if (!d_function->argumentRemoved(i+1)) { | |
583 TypeSystem::Ownership owner = d_function->ownership(d_function->implementingClass(), TypeSystem::TargetLangCode, i+1); | |
584 if (owner != TypeSystem::InvalidOwnership) { | |
585 s << INDENT << "if (" << arg->argumentName() << " !is null) {" << endl; | |
586 { | |
587 Indentation indent(INDENT); | |
588 if (arg->type()->isContainer()) | |
589 ;// qtd2 writeOwnershipForContainer(s, owner, arg); | |
590 else | |
591 s << INDENT << arg->argumentName() << "." << function_call_for_ownership(owner) << ";" << endl; | |
592 } | |
593 s << INDENT << "}" << endl; | |
594 } | |
595 /* | |
596 if (type->isArray()) { | |
597 s << INDENT << "if (" << arg->argumentName() << ".length != " << type->arrayElementCount() << ")" << endl | |
598 << INDENT << " " << "throw new IllegalArgumentException(\"Wrong number of elements in array. Found: \" + " | |
599 << arg->argumentName() << ".length + \", expected: " << type->arrayElementCount() << "\");" | |
600 << endl << endl; | |
601 } | |
602 | |
603 if (type->isEnum()) { | |
604 EnumTypeEntry *et = (EnumTypeEntry *) type->typeEntry(); | |
605 if (et->forceInteger()) { | |
606 if (!et->lowerBound().isEmpty()) { | |
607 s << INDENT << "if (" << arg->argumentName() << " < " << et->lowerBound() << ")" << endl | |
608 << INDENT << " throw new IllegalArgumentException(\"Argument " << arg->argumentName() | |
609 << " is less than lowerbound " << et->lowerBound() << "\");" << endl; | |
610 } | |
611 if (!et->upperBound().isEmpty()) { | |
612 s << INDENT << "if (" << arg->argumentName() << " > " << et->upperBound() << ")" << endl | |
613 << INDENT << " throw new IllegalArgumentException(\"Argument " << arg->argumentName() | |
614 << " is greated than upperbound " << et->upperBound() << "\");" << endl; | |
615 } | |
616 } | |
617 } | |
618 */ | |
619 } | |
620 } | |
621 | |
622 /* qtd2 | |
623 if (!d_function->isConstructor() && !d_function->isStatic()) { | |
624 s << INDENT << "if (nativeId() == 0)" << endl | |
625 << INDENT << " throw new QNoNativeResourcesException(\"Function call on incomplete object of type: \" +getClass().getName());" << endl; | |
626 } | |
627 */ | |
628 for (int i=0; i<arguments.size(); ++i) { | |
629 if (d_function->nullPointersDisabled(d_function->implementingClass(), i + 1)) { | |
630 s << INDENT << "/*if (" << arguments.at(i)->argumentName() << " is null)" << endl | |
631 << INDENT << " throw new NullPointerException(\"Argument '" << arguments.at(i)->argumentName() << "': null not expected.\"); */" << endl; | |
632 } | |
633 } | |
634 | |
635 QList<ReferenceCount> referenceCounts; | |
636 for (int i=0; i<arguments.size() + 1; ++i) { | |
637 referenceCounts = d_function->referenceCounts(d_function->implementingClass(), | |
638 i == 0 ? -1 : i); | |
639 | |
640 foreach (ReferenceCount refCount, referenceCounts) | |
641 writeReferenceCount(s, refCount, i == 0 ? "this" : arguments.at(i-1)->argumentName()); | |
642 } | |
643 | |
644 referenceCounts = d_function->referenceCounts(d_function->implementingClass(), 0); | |
645 AbstractMetaType *return_type = d_function->type(); | |
646 QString new_return_type = QString(d_function->typeReplaced(0)).replace('$', '.'); | |
647 bool has_return_type = new_return_type != "void" | |
648 && (!new_return_type.isEmpty() || return_type != 0); | |
649 // qtd TypeSystem::Ownership owner = d_function->ownership(d_function->implementingClass(), TypeSystem::TargetLangCode, 0); | |
650 | |
651 bool has_code_injections_at_the_end = false; | |
652 FunctionModificationList mods = get_function_modifications_for_class_hierarchy(d_function); | |
653 foreach (FunctionModification mod, mods) { | |
654 foreach (CodeSnip snip, mod.snips) { | |
655 if (snip.position == CodeSnip::End && snip.language == TypeSystem::TargetLangCode) { | |
656 has_code_injections_at_the_end = true; | |
657 break; | |
658 } | |
659 } | |
660 } | |
661 | |
662 // bool needs_return_variable = has_return_type | |
663 // && (owner != TypeSystem::InvalidOwnership || referenceCounts.size() > 0 || has_code_injections_at_the_end); | |
664 | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
665 if(return_type) { // qtd |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
666 if (return_type->isTargetLangString()) |
1 | 667 s << INDENT << "string res;" << endl; |
668 | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
669 if(return_type->name() == "QModelIndex") |
1 | 670 s << INDENT << "QModelIndex res;" << endl; |
81 | 671 else if (return_type->typeEntry()->isStructInD()) |
672 s << INDENT << return_type->name() << " res;" << endl; | |
1 | 673 |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
674 if(return_type->isContainer()) |
1 | 675 s << INDENT << this->translateType(d_function->type(), d_function->ownerClass(), NoOption) << " res;" << endl; |
676 } | |
677 | |
130
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
678 // returning string or a struct |
81 | 679 bool return_in_arg = return_type && (return_type->isTargetLangString() || |
680 return_type->name() == "QModelIndex" || | |
681 return_type->isContainer() || | |
682 return_type->typeEntry()->isStructInD()); | |
683 | |
130
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
684 // bool flag showing if we return value immediately, without any conversions |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
685 // which is commpon for primitive types, initially set up to return_in_arg, because in that case |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
686 // we don't need type conversions |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
687 bool returnImmediately = return_in_arg; |
81 | 688 |
1 | 689 s << INDENT; |
690 if ( (has_return_type && d_function->argumentReplaced(0).isEmpty() ) || d_function->isConstructor()) { //qtd | |
691 if(d_function->type() && d_function->type()->isQObject()) { // qtd | |
692 s << "void *__qt_return_value = "; | |
81 | 693 } else if(return_in_arg) // qtd |
1 | 694 ; |
81 | 695 else if (d_function->isConstructor()) { // qtd |
1 | 696 s << "void* __qt_return_value = "; |
81 | 697 } else if (return_type && return_type->isValue() && !return_type->typeEntry()->isStructInD()) { |
1 | 698 s << "void* __qt_return_value = "; |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
699 } else if (return_type && return_type->isVariant()) { |
1 | 700 s << "void* __qt_return_value = "; |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
701 } else if (return_type && ( return_type->isObject() || |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
702 (return_type->isNativePointer() && return_type->typeEntry()->isValue()) || |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
703 return_type->typeEntry()->isInterface()) ) { |
1 | 704 s << "void* __qt_return_value = "; |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
705 } else if (return_type && return_type->isArray()) { |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
706 s << return_type->arrayElementType()->name() + "* __qt_return_value = "; |
1 | 707 } else { |
130
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
708 returnImmediately = true; |
1 | 709 s << "return "; |
710 } | |
711 | |
712 if (return_type && return_type->isTargetLangEnum()) { | |
713 s << "cast(" << return_type->typeEntry()->qualifiedTargetLangName() << ") "; | |
714 }/* qtd2 flags else if (return_type && return_type->isTargetLangFlags()) { | |
715 s << "new " << return_type->typeEntry()->qualifiedTargetLangName() << "("; | |
716 }*/ | |
717 } | |
718 | |
719 bool useJumpTable = d_function->jumpTableId() != -1; | |
720 if (useJumpTable) { | |
721 // The native function returns the correct type, we only have | |
722 // java.lang.Object so we may have to cast... | |
723 QString signature = JumpTablePreprocessor::signature(d_function); | |
724 | |
725 // printf("return: %s::%s return=%p, replace-value=%s, replace-type=%s signature: %s\n", | |
726 // qPrintable(d_function->ownerClass()->name()), | |
727 // qPrintable(d_function->signature()), | |
728 // return_type, | |
729 // qPrintable(d_function->argumentReplaced(0)), | |
730 // qPrintable(new_return_type), | |
731 // qPrintable(signature)); | |
732 | |
733 if (has_return_type && signature.at(0) == 'L') { | |
734 if (new_return_type.length() > 0) { | |
735 // printf(" ---> replace-type: %s\n", qPrintable(new_return_type)); | |
736 s << "(" << new_return_type << ") "; | |
737 } else if (d_function->argumentReplaced(0).isEmpty()) { | |
738 // printf(" ---> replace-value\n"); | |
739 s << "(" << translateType(return_type, d_function->implementingClass()) << ") "; | |
740 } | |
741 } | |
742 | |
743 s << "JTbl." << JumpTablePreprocessor::signature(d_function) << "(" | |
744 << d_function->jumpTableId() << ", "; | |
745 | |
746 // Constructors and static functions don't have native id, but | |
747 // the functions expect them anyway, hence add '0'. Normal | |
748 // functions get their native ids added just below... | |
749 if (d_function->isConstructor() || d_function->isStatic()) | |
750 s << "0, "; | |
751 | |
752 } else { | |
753 /* qtd if (attributes & SuperCall) { | |
754 s << "super."; | |
755 }*/ | |
756 s << d_function->marshalledName() << "("; | |
757 } | |
758 | |
759 if (!d_function->isConstructor() && !d_function->isStatic()) | |
760 s << "nativeId"; | |
761 | |
762 if (d_function->isConstructor() && | |
763 ( d_function->implementingClass()->hasVirtualFunctions() | |
764 || d_function->implementingClass()->typeEntry()->isObject() ) ) { // qtd | |
765 s << "cast(void*) this"; | |
766 if (arguments.count() > 0) | |
767 s << ", "; | |
768 } | |
769 | |
770 if(return_in_arg) { // qtd | |
771 if (!d_function->isStatic() && !d_function->isConstructor()) // qtd | |
772 s << ", "; | |
773 s << "&res"; | |
774 } | |
775 | |
776 for (int i=0; i<arguments.count(); ++i) { | |
777 const AbstractMetaArgument *arg = arguments.at(i); | |
778 const AbstractMetaType *type = arg->type(); | |
779 const TypeEntry *te = type->typeEntry(); | |
780 | |
781 if (!d_function->argumentRemoved(i+1)) { | |
782 if (i > 0 || (!d_function->isStatic() && !d_function->isConstructor()) || return_in_arg) // qtd | |
783 s << ", "; | |
784 | |
785 // qtd | |
786 QString modified_type = d_function->typeReplaced(arg->argumentIndex() + 1); | |
787 if (!modified_type.isEmpty()) | |
788 modified_type = modified_type.replace('$', '.'); | |
789 | |
790 QString arg_name = arg->argumentName(); | |
791 | |
792 if (type->isVariant()) | |
793 s << arg_name << " is null ? null : " << arg_name << ".nativeId"; | |
794 else if (te->designatedInterface()) | |
795 s << arg_name << " is null ? null : " << arg_name << ".__ptr_" << te->designatedInterface()->name(); | |
796 else if (modified_type == "string" /* && type->fullName() == "char" */) { | |
797 s << "toStringz(" << arg_name << ")"; | |
81 | 798 } else if (type->isArray()) { |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
799 s << arg_name << ".ptr"; |
81 | 800 } else if(type->isContainer()) { |
1 | 801 const ContainerTypeEntry *cte = |
802 static_cast<const ContainerTypeEntry *>(te); | |
803 if(isLinearContainer(cte)) | |
804 s << QString("%1.ptr, %1.length").arg(arg_name); | |
81 | 805 } else if (type->typeEntry()->qualifiedCppName() == "QChar") { |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
806 s << arg_name; |
81 | 807 } else if (type->isTargetLangString() || (te && te->qualifiedCppName() == "QString")) { |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
808 s << arg_name; |
81 | 809 } else if (type->isTargetLangEnum() || type->isTargetLangFlags()) { |
1 | 810 s << arg_name; |
811 // qtd s << arg->argumentName() << ".value()"; | |
812 } else if (!type->hasNativeId() && !(te->isValue() && type->isNativePointer())) { // qtd2 hack for QStyleOption not being a nativeId based for some reason | |
813 s << arg_name; | |
814 } else if (te->isStructInD()) { | |
815 s << arg_name; | |
816 } else { | |
817 bool force_abstract = te->isComplex() && (((static_cast<const ComplexTypeEntry *>(te))->typeFlags() & ComplexTypeEntry::ForceAbstract) != 0); | |
818 if (!force_abstract) { | |
819 s << arg_name << " is null ? null : "; | |
820 } // else if (value type is abstract) then we will get a null pointer exception, which is all right | |
821 | |
822 s << arg_name << ".nativeId"; | |
823 } | |
824 } | |
825 } | |
826 | |
827 if (useJumpTable) { | |
828 if ((!d_function->isConstructor() && !d_function->isStatic()) || arguments.size() > 0) | |
829 s << ", "; | |
830 | |
831 if (d_function->isStatic()) | |
832 s << "null"; | |
833 else | |
834 s << "this"; | |
835 } | |
836 | |
837 s << ")"; | |
838 | |
839 if ( !d_function->argumentReplaced(0).isEmpty() ) { | |
840 s << ";" << endl; | |
841 s << INDENT << "return " << d_function->argumentReplaced(0) << ";" << endl; | |
842 return; | |
843 } | |
844 | |
845 // qtd2 if (return_type && (/* qtdreturn_type->isTargetLangEnum() ||*/ return_type->isTargetLangFlags())) | |
846 // s << ")"; | |
847 | |
848 s << ";" << endl; | |
849 | |
850 /* qtd2 | |
851 if (needs_return_variable) { | |
852 if (owner != TypeSystem::InvalidOwnership) { | |
853 s << INDENT << "if (__qt_return_value != null) {" << endl; | |
854 if (return_type->isContainer()) | |
855 writeOwnershipForContainer(s, owner, return_type, "__qt_return_value"); | |
856 else | |
857 s << INDENT << " __qt_return_value." << function_call_for_ownership(owner) << ";" << endl; | |
858 s << INDENT << "}" << endl; | |
859 } | |
860 s << INDENT << "return __qt_return_value;" << endl; | |
861 } | |
862 */ | |
863 if (d_function->isConstructor()) { | |
864 TypeSystem::Ownership owner = d_function->ownership(d_function->implementingClass(), TypeSystem::TargetLangCode, -1); | |
865 if (owner != TypeSystem::InvalidOwnership && d_function->isConstructor()) | |
866 s << INDENT << "this." << function_call_for_ownership(owner) << ";" << endl; | |
867 } | |
868 | |
130
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
869 // return value marschalling |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
870 if(return_type) { |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
871 if (!returnImmediately && !d_function->storeResult()) { |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
872 s << INDENT; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
873 QString modified_type = d_function->typeReplaced(0); |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
874 if (modified_type.isEmpty()) |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
875 s << translateType(d_function->type(), d_function->implementingClass()); |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
876 else |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
877 s << modified_type.replace('$', '.'); |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
878 s << " __d_return_value = "; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
879 } |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
880 |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
881 if ( ( has_return_type && d_function->argumentReplaced(0).isEmpty() )) // qtd |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
882 if(return_type->isQObject()) |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
883 s << "qtd_" << return_type->name() << "_from_ptr(__qt_return_value);" << endl; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
884 |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
885 if (return_type->isValue() && !return_type->typeEntry()->isStructInD()) |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
886 s << "new " << return_type->name() << "(__qt_return_value, false);" << endl; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
887 |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
888 if (return_type->isVariant()) |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
889 s << "new QVariant(__qt_return_value, false);" << endl; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
890 |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
891 if (return_type->isNativePointer() && return_type->typeEntry()->isValue()) |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
892 s << "new " << return_type->name() << "(__qt_return_value, true);" << endl; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
893 |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
894 if (return_type->isObject()) { |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
895 if(d_function->storeResult()) |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
896 s << INDENT << QString("__m_%1.nativeId = __qt_return_value;").arg(d_function->name()) << endl |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
897 << INDENT << QString("return __m_%1;").arg(d_function->name()) << endl; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
898 else |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
899 s << "qtd_" << return_type->name() << "_from_ptr(__qt_return_value);" << endl; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
900 s << endl; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
901 } |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
902 |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
903 if (return_type->isArray()) { |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
904 s << "__qt_return_value[0 .. " << return_type->arrayElementCount() << "];" << endl; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
905 } |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
906 |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
907 foreach (ReferenceCount referenceCount, referenceCounts) { |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
908 writeReferenceCount(s, referenceCount, "__d_return_value"); |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
909 } |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
910 |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
911 if (!returnImmediately && !d_function->storeResult()) |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
912 s << INDENT << "return __d_return_value;" << endl; |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
913 } |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
914 writeInjectedCode(s, d_function, CodeSnip::End); |
7ae9bc9d6935
reference counting for return values. applied to QMenu
eldar
parents:
112
diff
changeset
|
915 |
1 | 916 if(return_in_arg) // qtd |
917 s << INDENT << "return res;" << endl; | |
918 } | |
919 | |
920 void DGenerator::retrieveModifications(const AbstractMetaFunction *d_function, | |
921 const AbstractMetaClass *d_class, | |
922 uint *exclude_attributes, | |
923 uint *include_attributes) const | |
924 { | |
925 FunctionModificationList mods = d_function->modifications(d_class); | |
926 // printf("name: %s has %d mods\n", qPrintable(d_function->signature()), mods.size()); | |
927 foreach (FunctionModification mod, mods) { | |
928 if (mod.isAccessModifier()) { | |
929 // printf(" -> access mod to %x\n", mod.modifiers); | |
930 *exclude_attributes |= AbstractMetaAttributes::Public | |
931 | AbstractMetaAttributes::Protected | |
932 | AbstractMetaAttributes::Private | |
933 | AbstractMetaAttributes::Friendly; | |
934 | |
935 if (mod.isPublic()) | |
936 *include_attributes |= AbstractMetaAttributes::Public; | |
937 else if (mod.isProtected()) | |
938 *include_attributes |= AbstractMetaAttributes::Protected; | |
939 else if (mod.isPrivate()) | |
940 *include_attributes |= AbstractMetaAttributes::Private; | |
941 else if (mod.isFriendly()) | |
942 *include_attributes |= AbstractMetaAttributes::Friendly; | |
943 } | |
944 | |
945 if (mod.isFinal()) { | |
946 *include_attributes |= AbstractMetaAttributes::FinalInTargetLang; | |
947 } else if (mod.isNonFinal()) { | |
948 *exclude_attributes |= AbstractMetaAttributes::FinalInTargetLang; | |
949 } | |
950 } | |
951 | |
952 *exclude_attributes &= ~(*include_attributes); | |
953 } | |
954 | |
955 QString DGenerator::functionSignature(const AbstractMetaFunction *d_function, | |
956 uint included_attributes, uint excluded_attributes, | |
957 Option option, | |
958 int arg_count) | |
959 { | |
960 AbstractMetaArgumentList arguments = d_function->arguments(); | |
961 int argument_count = arg_count < 0 ? arguments.size() : arg_count; | |
962 | |
963 QString result; | |
964 QTextStream s(&result); | |
965 QString functionName = d_function->isConstructor() ? "this" : d_function->name(); // qtd | |
966 // The actual function | |
967 if (!(d_function->isEmptyFunction() || d_function->isNormal() || d_function->isSignal())) | |
968 option = Option(option | SkipReturnType); | |
969 writeFunctionAttributes(s, d_function, included_attributes, excluded_attributes, option); | |
970 | |
971 s << functionName << "("; | |
972 writeFunctionArguments(s, d_function, argument_count, option); | |
973 s << ")"; | |
974 | |
975 return result; | |
976 } | |
977 | |
978 void DGenerator::setupForFunction(const AbstractMetaFunction *d_function, | |
979 uint *included_attributes, | |
980 uint *excluded_attributes) const | |
981 { | |
982 *excluded_attributes |= d_function->ownerClass()->isInterface() || d_function->isConstructor() | |
983 ? AbstractMetaAttributes::Native | AbstractMetaAttributes::Final | |
984 : 0; | |
985 if (d_function->ownerClass()->isInterface()) | |
986 *excluded_attributes |= AbstractMetaAttributes::Abstract; | |
987 if (d_function->needsCallThrough()) | |
988 *excluded_attributes |= AbstractMetaAttributes::Native; | |
989 | |
990 const AbstractMetaClass *d_class = d_function->ownerClass(); | |
991 retrieveModifications(d_function, d_class, excluded_attributes, included_attributes); | |
992 } | |
993 | |
994 void DGenerator::writeReferenceCount(QTextStream &s, const ReferenceCount &refCount, | |
995 const QString &argumentName) | |
996 { | |
997 if (refCount.action == ReferenceCount::Ignore) | |
998 return; | |
999 | |
1000 QString refCountVariableName = refCount.variableName; | |
1001 if (!refCount.declareVariable.isEmpty() && refCount.action != ReferenceCount::Set) { | |
1002 s << INDENT << "auto __rcTmp = " << refCountVariableName << ";" << endl; | |
1003 refCountVariableName = "__rcTmp"; | |
1004 } | |
1005 | |
1006 if (refCount.action != ReferenceCount::Set) { | |
1007 s << INDENT << "if (" << argumentName << " !is null"; | |
1008 | |
1009 if (!refCount.conditional.isEmpty()) | |
1010 s << " && " << refCount.conditional; | |
1011 | |
1012 s << ") {" << endl; | |
1013 } else { | |
1014 if (!refCount.conditional.isEmpty()) | |
1015 s << INDENT << "if (" << refCount.conditional << ") "; | |
1016 s << INDENT << "{" << endl; | |
1017 } | |
1018 | |
1019 { | |
1020 Indentation indent(INDENT); | |
1021 switch (refCount.action) { | |
1022 case ReferenceCount::Add: | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
1023 s << INDENT << refCountVariableName << " ~= cast(Object) " << argumentName << ";" << endl; |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
1024 break; |
1 | 1025 case ReferenceCount::AddAll: |
1026 s << INDENT << refCountVariableName << " ~= " << argumentName << ";" << endl; | |
1027 break; | |
1028 case ReferenceCount::Remove: | |
1029 s << INDENT << "remove(" << refCountVariableName | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
1030 << ", cast(Object) " << argumentName << ");" << endl; |
1 | 1031 break; |
1032 case ReferenceCount::Set: | |
1033 { | |
1034 if (refCount.declareVariable.isEmpty()) | |
1035 s << INDENT << refCount.variableName << " = cast(Object) " << argumentName << ";" << endl; | |
1036 else | |
1037 s << INDENT << refCountVariableName << " = cast(Object) " << argumentName << ";" << endl; | |
1038 } | |
1039 default: | |
1040 break; | |
1041 }; | |
1042 } | |
1043 s << INDENT << "}" << endl; | |
1044 } | |
1045 | |
1046 void DGenerator::writeFunction(QTextStream &s, const AbstractMetaFunction *d_function, | |
1047 uint included_attributes, uint excluded_attributes) | |
1048 { | |
1049 s << endl; | |
1050 | |
1051 if (d_function->isModifiedRemoved(TypeSystem::TargetLangCode)) | |
1052 return ; | |
1053 QString functionName = d_function->name(); | |
1054 setupForFunction(d_function, &included_attributes, &excluded_attributes); | |
1055 | |
1056 if (!d_function->ownerClass()->isInterface()) { | |
1057 // qtd2 writeEnumOverload(s, d_function, included_attributes, excluded_attributes); | |
1058 // qtd writeFunctionOverloads(s, d_function, included_attributes, excluded_attributes); | |
1059 } | |
1060 /* qtd | |
1061 static QRegExp regExp("^(insert|set|take|add|remove|install).*"); | |
1062 | |
1063 if (regExp.exactMatch(d_function->name())) { | |
1064 AbstractMetaArgumentList arguments = d_function->arguments(); | |
1065 | |
1066 const AbstractMetaClass *c = d_function->implementingClass(); | |
1067 bool hasObjectTypeArgument = false; | |
1068 foreach (AbstractMetaArgument *argument, arguments) { | |
1069 TypeSystem::Ownership d_ownership = d_function->ownership(c, TypeSystem::TargetLangCode, argument->argumentIndex()+1); | |
1070 TypeSystem::Ownership shell_ownership = d_function->ownership(c, TypeSystem::ShellCode, argument->argumentIndex()+1); | |
1071 | |
1072 if (argument->type()->typeEntry()->isObject() | |
1073 && d_ownership == TypeSystem::InvalidOwnership | |
1074 && shell_ownership == TypeSystem::InvalidOwnership) { | |
1075 hasObjectTypeArgument = true; | |
1076 break; | |
1077 } | |
1078 } | |
1079 | |
1080 if (hasObjectTypeArgument | |
1081 && !d_function->isAbstract() | |
1082 && d_function->referenceCounts(d_function->implementingClass()).size() == 0) { | |
1083 m_reference_count_candidate_functions.append(d_function); | |
1084 } | |
1085 } | |
1086 | |
1087 | |
1088 if (m_doc_parser) { | |
1089 QString signature = functionSignature(d_function, | |
1090 included_attributes | NoBlockedSlot, | |
1091 excluded_attributes); | |
1092 s << m_doc_parser->documentationForFunction(signature) << endl; | |
1093 } | |
1094 | |
1095 const QPropertySpec *spec = d_function->propertySpec(); | |
1096 if (spec && d_function->modifiedName() == d_function->originalName()) { | |
1097 if (d_function->isPropertyReader()) { | |
1098 s << " @qt.QtPropertyReader(name=\"" << spec->name() << "\")" << endl; | |
1099 if (!spec->designable().isEmpty()) | |
1100 s << " @qt.QtPropertyDesignable(\"" << spec->designable() << "\")" << endl; | |
1101 } else if (d_function->isPropertyWriter()) { | |
1102 s << " @qt.QtPropertyWriter(name=\"" << spec->name() << "\")" << endl; | |
1103 } else if (d_function->isPropertyResetter()) { | |
1104 s << " @qt.QtPropertyResetter(name=\"" << spec->name() << "\")" | |
1105 << endl; | |
1106 } | |
1107 } | |
1108 */ | |
1109 s << functionSignature(d_function, included_attributes, excluded_attributes); | |
1110 | |
1111 if (d_function->isConstructor()) { | |
1112 writeConstructorContents(s, d_function); | |
1113 } else if (d_function->needsCallThrough() || d_function->isStatic()) { // qtd | |
1114 if (d_function->isAbstract()) { | |
1115 s << ";" << endl; | |
1116 } else { | |
1117 s << " {" << endl; | |
1118 { | |
1119 Indentation indent(INDENT); | |
1120 writeJavaCallThroughContents(s, d_function); | |
1121 } | |
1122 s << INDENT << "}" << endl; | |
1123 } | |
1124 | |
1125 /* qtd | |
1126 if (d_function->jumpTableId() == -1) { | |
1127 writePrivateNativeFunction(s, d_function); | |
1128 } | |
1129 */ | |
1130 } else { | |
1131 s << ";" << endl; | |
1132 } | |
1133 } | |
1134 | |
1135 static void write_equals_parts(QTextStream &s, const AbstractMetaFunctionList &lst, char prefix, bool *first) { | |
1136 foreach (AbstractMetaFunction *f, lst) { | |
1137 AbstractMetaArgument *arg = f->arguments().at(0); | |
1138 QString type = f->typeReplaced(1); | |
1139 if (type.isEmpty()) | |
1140 type = arg->type()->typeEntry()->qualifiedTargetLangName(); | |
1141 s << INDENT << (*first ? "if" : "else if") << " (other instanceof " << type << ")" << endl | |
1142 << INDENT << " return "; | |
1143 if (prefix != 0) s << prefix; | |
1144 s << f->name() << "((" << type << ") other);" << endl; | |
1145 *first = false; | |
1146 } | |
1147 } | |
1148 | |
1149 static void write_compareto_parts(QTextStream &s, const AbstractMetaFunctionList &lst, int value, bool *first) { | |
1150 foreach (AbstractMetaFunction *f, lst) { | |
1151 AbstractMetaArgument *arg = f->arguments().at(0); | |
1152 QString type = f->typeReplaced(1); | |
1153 if (type.isEmpty()) | |
1154 type = arg->type()->typeEntry()->qualifiedTargetLangName(); | |
1155 s << INDENT << (*first ? "if" : "else if") << " (other instanceof " << type << ") {" << endl | |
1156 << INDENT << " if (" << f->name() << "((" << type << ") other)) return " << value << ";" << endl | |
1157 << INDENT << " else return " << -value << ";" << endl | |
1158 << INDENT << "}" << endl; | |
1159 *first = false; | |
1160 } | |
1161 s << INDENT << "throw new ClassCastException();" << endl; | |
1162 } | |
1163 | |
1164 bool DGenerator::isComparable(const AbstractMetaClass *cls) const | |
1165 { | |
1166 AbstractMetaFunctionList eq_functions = cls->equalsFunctions(); | |
1167 AbstractMetaFunctionList neq_functions = cls->notEqualsFunctions(); | |
1168 | |
1169 // Write the comparable functions | |
1170 AbstractMetaFunctionList ge_functions = cls->greaterThanFunctions(); | |
1171 AbstractMetaFunctionList geq_functions = cls->greaterThanEqFunctions(); | |
1172 AbstractMetaFunctionList le_functions = cls->lessThanFunctions(); | |
1173 AbstractMetaFunctionList leq_functions = cls->lessThanEqFunctions(); | |
1174 | |
1175 bool hasEquals = eq_functions.size() || neq_functions.size(); | |
1176 bool isComparable = hasEquals | |
1177 ? ge_functions.size() || geq_functions.size() || le_functions.size() || leq_functions.size() | |
1178 : geq_functions.size() == 1 && leq_functions.size() == 1; | |
1179 | |
1180 return isComparable; | |
1181 } | |
1182 | |
1183 | |
1184 void DGenerator::writeJavaLangObjectOverrideFunctions(QTextStream &s, | |
1185 const AbstractMetaClass *cls) | |
1186 { | |
1187 AbstractMetaFunctionList eq_functions = cls->equalsFunctions(); | |
1188 AbstractMetaFunctionList neq_functions = cls->notEqualsFunctions(); | |
1189 | |
1190 if (eq_functions.size() || neq_functions.size()) { | |
1191 s << endl | |
1192 << INDENT << "@SuppressWarnings(\"unchecked\")" << endl | |
1193 << INDENT << "@Override" << endl | |
1194 << INDENT << "public boolean equals(Object other) {" << endl; | |
1195 bool first = true; | |
1196 write_equals_parts(s, eq_functions, (char) 0, &first); | |
1197 write_equals_parts(s, neq_functions, '!', &first); | |
1198 s << INDENT << " return false;" << endl | |
1199 << INDENT << "}" << endl << endl; | |
1200 } | |
1201 | |
1202 // Write the comparable functions | |
1203 AbstractMetaFunctionList ge_functions = cls->greaterThanFunctions(); | |
1204 AbstractMetaFunctionList geq_functions = cls->greaterThanEqFunctions(); | |
1205 AbstractMetaFunctionList le_functions = cls->lessThanFunctions(); | |
1206 AbstractMetaFunctionList leq_functions = cls->lessThanEqFunctions(); | |
1207 | |
1208 bool hasEquals = eq_functions.size() || neq_functions.size(); | |
1209 bool comparable = isComparable(cls); | |
1210 if (comparable) { | |
1211 s << INDENT << "public int compareTo(Object other) {" << endl; | |
1212 { | |
1213 Indentation indent(INDENT); | |
1214 if (hasEquals) { | |
1215 s << INDENT << "if (equals(other)) return 0;" << endl; | |
1216 bool first = false; | |
1217 if (le_functions.size()) { | |
1218 write_compareto_parts(s, le_functions, -1, &first); | |
1219 } else if (ge_functions.size()) { | |
1220 write_compareto_parts(s, ge_functions, 1, &first); | |
1221 } else if (leq_functions.size()) { | |
1222 write_compareto_parts(s, leq_functions, -1, &first); | |
1223 } else if (geq_functions.size()) { | |
1224 write_compareto_parts(s, geq_functions, 1, &first); | |
1225 } | |
1226 | |
1227 } else if (le_functions.size() == 1) { | |
1228 QString className = cls->typeEntry()->qualifiedTargetLangName(); | |
1229 s << INDENT << "if (operator_less((" << className << ") other)) return -1;" << endl | |
1230 << INDENT << "else if (((" << className << ") other).operator_less(this)) return 1;" << endl | |
1231 << INDENT << "else return 0;" << endl; | |
1232 | |
1233 } else if (geq_functions.size() == 1 && leq_functions.size()) { | |
1234 QString className = cls->typeEntry()->qualifiedTargetLangName(); | |
1235 s << INDENT << "boolean less = operator_less_or_equal((" << className << ") other);" << endl | |
1236 << INDENT << "boolean greater = operator_greater_or_equal((" << className << ") other);" << endl | |
1237 << INDENT << "if (less && greater) return 0;" << endl | |
1238 << INDENT << "else if (less) return -1;" << endl | |
1239 << INDENT << "else return 1;" << endl; | |
1240 } | |
1241 } | |
1242 | |
1243 s << INDENT << "}" << endl; | |
1244 } | |
1245 | |
1246 | |
1247 if (cls->hasHashFunction()) { | |
1248 AbstractMetaFunctionList hashcode_functions = cls->queryFunctionsByName("hashCode"); | |
1249 bool found = false; | |
1250 foreach (const AbstractMetaFunction *function, hashcode_functions) { | |
1251 if (function->actualMinimumArgumentCount() == 0) { | |
1252 found = true; | |
1253 break; | |
1254 } | |
1255 } | |
1256 | |
1257 if (!found) { | |
1258 s << endl | |
1259 << INDENT << "@Override" << endl | |
1260 << INDENT << "public int hashCode() {" << endl | |
1261 << INDENT << " if (nativeId() == 0)" << endl | |
1262 << INDENT << " throw new QNoNativeResourcesException(\"Function call on incomplete object of type: \" +getClass().getName());" << endl | |
1263 << INDENT << " return __qt_hashCode(nativeId());" << endl | |
1264 << INDENT << "}" << endl | |
1265 << INDENT << "native int __qt_hashCode(long __this_nativeId);" << endl; | |
1266 } | |
1267 } | |
1268 | |
1269 // Qt has a standard toString() conversion in QVariant? | |
1270 QVariant::Type type = QVariant::nameToType(cls->qualifiedCppName().toLatin1()); | |
1271 if (QVariant(type).canConvert(QVariant::String) && !cls->hasToStringCapability()) { | |
1272 AbstractMetaFunctionList tostring_functions = cls->queryFunctionsByName("toString"); | |
1273 bool found = false; | |
1274 foreach (const AbstractMetaFunction *function, tostring_functions) { | |
1275 if (function->actualMinimumArgumentCount() == 0) { | |
1276 found = true; | |
1277 break; | |
1278 } | |
1279 } | |
1280 | |
1281 if (!found) { | |
1282 s << endl | |
1283 << INDENT << "@Override" << endl | |
1284 << INDENT << "public String toString() {" << endl | |
1285 << INDENT << " if (nativeId() == 0)" << endl | |
1286 << INDENT << " throw new QNoNativeResourcesException(\"Function call on incomplete object of type: \" +getClass().getName());" << endl | |
1287 << INDENT << " return __qt_toString(nativeId());" << endl | |
1288 << INDENT << "}" << endl | |
1289 << INDENT << "native String __qt_toString(long __this_nativeId);" << endl; | |
1290 } | |
1291 } | |
1292 } | |
1293 | |
1294 void DGenerator::writeEnumOverload(QTextStream &s, const AbstractMetaFunction *d_function, | |
1295 uint include_attributes, uint exclude_attributes) | |
1296 { | |
1297 AbstractMetaArgumentList arguments = d_function->arguments(); | |
1298 | |
1299 if ((d_function->implementingClass() != d_function->declaringClass()) | |
1300 || ((!d_function->isNormal() && !d_function->isConstructor()) || d_function->isEmptyFunction() || d_function->isAbstract())) { | |
1301 return ; | |
1302 } | |
1303 | |
1304 | |
1305 int option = 0; | |
1306 if (d_function->isConstructor()) | |
1307 option = Option(option | SkipReturnType); | |
1308 else | |
1309 include_attributes |= AbstractMetaAttributes::FinalInTargetLang; | |
1310 | |
1311 int generate_enum_overload = -1; | |
1312 for (int i=0; i<arguments.size(); ++i) | |
1313 generate_enum_overload = arguments.at(i)->type()->isTargetLangFlags() ? i : -1; | |
1314 | |
1315 if (generate_enum_overload >= 0) { | |
1316 if (m_doc_parser) { | |
1317 // steal documentation from main function | |
1318 QString signature = functionSignature(d_function, | |
1319 include_attributes | NoBlockedSlot, | |
1320 exclude_attributes); | |
1321 s << m_doc_parser->documentationForFunction(signature) << endl; | |
1322 } | |
1323 | |
1324 s << endl; | |
1325 | |
1326 writeFunctionAttributes(s, d_function, include_attributes, exclude_attributes, option); | |
1327 s << d_function->name() << "("; | |
1328 if (generate_enum_overload > 0) { | |
1329 writeFunctionArguments(s, d_function, generate_enum_overload); | |
1330 s << ", "; | |
1331 } | |
1332 | |
1333 // Write the ellipsis convenience argument | |
1334 AbstractMetaArgument *affected_arg = arguments.at(generate_enum_overload); | |
1335 EnumTypeEntry *originator = ((FlagsTypeEntry *)affected_arg->type()->typeEntry())->originator(); | |
1336 | |
1337 s << originator->javaPackage() << "." << originator->javaQualifier() << "." << originator->targetLangName() | |
1338 << " ... " << affected_arg->argumentName() << ") {" << endl; | |
1339 | |
1340 s << " "; | |
1341 QString new_return_type = d_function->typeReplaced(0); | |
1342 if (new_return_type != "void" && (!new_return_type.isEmpty() || d_function->type() != 0)) | |
1343 s << "return "; | |
1344 | |
1345 if (d_function->isConstructor()) { | |
1346 s << "this"; | |
1347 } else { | |
1348 if (d_function->isStatic()) | |
1349 s << d_function->implementingClass()->fullName() << "."; | |
1350 else | |
1351 s << "this."; | |
1352 s << d_function->name(); | |
1353 } | |
1354 | |
1355 s << "("; | |
1356 for (int i=0; i<generate_enum_overload; ++i) { | |
1357 s << arguments.at(i)->argumentName() << ", "; | |
1358 } | |
1359 s << "new " << affected_arg->type()->fullName() << "(" << affected_arg->argumentName() << "));" << endl | |
1360 << " }" << endl; | |
1361 } | |
1362 } | |
1363 | |
1364 void DGenerator::writeInstantiatedType(QTextStream &s, const AbstractMetaType *abstractMetaType) const | |
1365 { | |
1366 Q_ASSERT(abstractMetaType != 0); | |
1367 | |
1368 const TypeEntry *type = abstractMetaType->typeEntry(); | |
1369 s << type->qualifiedTargetLangName(); | |
1370 | |
1371 if (abstractMetaType->hasInstantiations()) { | |
1372 s << "<"; | |
1373 QList<AbstractMetaType *> instantiations = abstractMetaType->instantiations(); | |
1374 for(int i=0; i<instantiations.size(); ++i) { | |
1375 if (i > 0) | |
1376 s << ", "; | |
1377 | |
1378 writeInstantiatedType(s, instantiations.at(i)); | |
1379 } | |
1380 s << ">"; | |
1381 } | |
1382 } | |
1383 | |
1384 void DGenerator::writeFunctionOverloads(QTextStream &s, const AbstractMetaFunction *d_function, | |
1385 uint include_attributes, uint exclude_attributes) | |
1386 { | |
1387 AbstractMetaArgumentList arguments = d_function->arguments(); | |
1388 int argument_count = arguments.size(); | |
1389 | |
1390 // We only create the overloads for the class that actually declares the function | |
1391 // unless this is an interface, in which case we create the overloads for all | |
1392 // classes that directly implement the interface. | |
1393 const AbstractMetaClass *decl_class = d_function->declaringClass(); | |
1394 if (decl_class->isInterface()) { | |
1395 AbstractMetaClassList interfaces = d_function->implementingClass()->interfaces(); | |
1396 foreach (AbstractMetaClass *iface, interfaces) { | |
1397 if (iface == decl_class) { | |
1398 decl_class = d_function->implementingClass(); | |
1399 break; | |
1400 } | |
1401 } | |
1402 } | |
1403 if (decl_class != d_function->implementingClass()) | |
1404 return; | |
1405 | |
1406 // Figure out how many functions we need to write out, | |
1407 // One extra for each default argument. | |
1408 int overload_count = 0; | |
1409 uint excluded_attributes = AbstractMetaAttributes::Abstract | |
1410 | AbstractMetaAttributes::Native | |
1411 | exclude_attributes; | |
1412 uint included_attributes = (d_function->isConstructor() ? 0 : AbstractMetaAttributes::Final) | include_attributes; | |
1413 | |
1414 for (int i=0; i<argument_count; ++i) { | |
1415 if (!arguments.at(i)->defaultValueExpression().isEmpty() && !d_function->argumentRemoved(i+1)) | |
1416 ++overload_count; | |
1417 } | |
1418 Q_ASSERT(overload_count <= argument_count); | |
1419 for (int i=0; i<overload_count; ++i) { | |
1420 int used_arguments = argument_count - i - 1; | |
1421 | |
1422 QString signature = functionSignature(d_function, included_attributes, | |
1423 excluded_attributes, | |
1424 d_function->isEmptyFunction() | |
1425 || d_function->isNormal() | |
1426 || d_function->isSignal() ? NoOption | |
1427 : SkipReturnType, | |
1428 used_arguments); | |
1429 | |
1430 s << endl; | |
1431 if (m_doc_parser) { | |
1432 s << m_doc_parser->documentationForFunction(signature) << endl; | |
1433 } | |
1434 | |
1435 s << signature << " {\n "; | |
1436 QString new_return_type = d_function->typeReplaced(0); | |
1437 if (new_return_type != "void" && (!new_return_type.isEmpty() || d_function->type())) | |
1438 s << "return "; | |
1439 if (d_function->isConstructor()) | |
1440 s << "this"; | |
1441 else | |
1442 s << d_function->name(); | |
1443 s << "("; | |
1444 | |
1445 int written_arguments = 0; | |
1446 for (int j=0; j<argument_count; ++j) { | |
1447 if (!d_function->argumentRemoved(j+1)) { | |
1448 if (written_arguments++ > 0) | |
1449 s << ", "; | |
1450 | |
1451 if (j < used_arguments) { | |
1452 s << arguments.at(j)->argumentName(); | |
1453 } else { | |
1454 AbstractMetaType *arg_type = 0; | |
1455 QString modified_type = d_function->typeReplaced(j+1); | |
1456 if (modified_type.isEmpty()) { | |
1457 arg_type = arguments.at(j)->type(); | |
1458 if (arg_type->isNativePointer()) { | |
1459 s << "(qt.QNativePointer)"; | |
1460 } else { | |
1461 const AbstractMetaType *abstractMetaType = arguments.at(j)->type(); | |
1462 const TypeEntry *type = abstractMetaType->typeEntry(); | |
1463 if (type->designatedInterface()) | |
1464 type = type->designatedInterface(); | |
1465 if (!type->isEnum() && !type->isFlags()) { | |
1466 s << "("; | |
1467 writeInstantiatedType(s, abstractMetaType); | |
1468 s << ")"; | |
1469 } | |
1470 } | |
1471 } else { | |
1472 s << "(" << modified_type.replace('$', '.') << ")"; | |
1473 } | |
1474 | |
1475 QString defaultExpr = arguments.at(j)->defaultValueExpression(); | |
1476 | |
1477 int pos = defaultExpr.indexOf("."); | |
1478 if (pos > 0) { | |
1479 QString someName = defaultExpr.left(pos); | |
1480 ComplexTypeEntry *ctype = | |
1481 TypeDatabase::instance()->findComplexType(someName); | |
1482 QString replacement; | |
1483 if (ctype != 0 && ctype->isVariant()) | |
1484 replacement = "qt.QVariant."; | |
1485 else if (ctype != 0) | |
1486 replacement = ctype->javaPackage() + "." + ctype->targetLangName() + "."; | |
1487 else | |
1488 replacement = someName + "."; | |
1489 defaultExpr = defaultExpr.replace(someName + ".", replacement); | |
1490 } | |
1491 | |
1492 if (arg_type != 0 && arg_type->isFlags()) { | |
1493 s << "new " << arg_type->fullName() << "(" << defaultExpr << ")"; | |
1494 } else { | |
1495 s << defaultExpr; | |
1496 } | |
1497 } | |
1498 } | |
1499 } | |
1500 s << ");\n }" << endl; | |
1501 } | |
1502 } | |
1503 | |
1504 const TypeEntry* DGenerator::fixedTypeEntry(const TypeEntry *type) | |
1505 { | |
1506 if (!type) | |
1507 return NULL; | |
1508 if (type->designatedInterface()) | |
1509 return type; | |
1510 else if (type->isEnum()) { | |
1511 const EnumTypeEntry *te = static_cast<const EnumTypeEntry *>(type); | |
1512 TypeEntry *ownerTe = TypeDatabase::instance()->findType(te->qualifier()); | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
1513 if(ownerTe) |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
1514 typeEntriesEnums << ownerTe; |
1 | 1515 return NULL; |
1516 // return ownerTe; | |
1517 } else if (type->isFlags()) { | |
1518 const FlagsTypeEntry *te = static_cast<const FlagsTypeEntry *>(type); | |
1519 TypeEntry *ownerTe = TypeDatabase::instance()->findType(te->qualifier()); | |
1520 return NULL; | |
1521 // return ownerTe; | |
1522 } else //if (type->isObject()) | |
1523 return type; | |
1524 // else return NULL; | |
1525 } | |
1526 | |
1527 void DGenerator::addInstantiations(const AbstractMetaType* d_type) | |
1528 { | |
1529 if (d_type->isContainer()) { | |
1530 QList<AbstractMetaType *> args = d_type->instantiations(); | |
1531 for (int i=0; i<args.size(); ++i) { | |
1532 const TypeEntry *type = fixedTypeEntry(args.at(i)->typeEntry()); | |
1533 if (type) | |
1534 typeEntries.insert(type); | |
1535 } | |
1536 } | |
1537 } | |
1538 | |
1539 void DGenerator::addTypeEntry(const AbstractMetaClass *d_class, const AbstractMetaFunction *function, QSet<const TypeEntry*> &typeEntries) | |
1540 { | |
1541 // If a method in an interface class is modified to be private, this should | |
1542 // not be present in the interface at all, only in the implementation. | |
1543 if (d_class->isInterface()) { | |
1544 uint includedAttributes = 0; | |
1545 uint excludedAttributes = 0; | |
1546 retrieveModifications(function, d_class, &excludedAttributes, &includedAttributes); | |
1547 if (includedAttributes & AbstractMetaAttributes::Private) | |
1548 return; | |
1549 } | |
1550 | |
1551 if (notWrappedYet(function)) // qtd2 | |
1552 return; | |
1553 | |
1554 // return type for function | |
1555 if (function->type()) { | |
1556 addInstantiations(function->type()); | |
1557 const TypeEntry *type = fixedTypeEntry(function->type()->typeEntry()); | |
1558 if (type) | |
1559 typeEntries.insert(type); | |
1560 } | |
1561 | |
1562 AbstractMetaArgumentList arguments = function->arguments(); | |
1563 for (int i=0; i<arguments.count(); ++i) { | |
1564 const AbstractMetaArgument *arg = arguments.at(i); | |
1565 addInstantiations(arg->type()); | |
1566 const TypeEntry *type = fixedTypeEntry(arg->type()->typeEntry()); | |
1567 if (type) | |
1568 typeEntries.insert(type); | |
1569 } | |
1570 } | |
1571 | |
1572 void DGenerator::fillRequiredImports(const AbstractMetaClass *d_class) | |
1573 { | |
1574 if (m_recursive < 2) { | |
1575 typeEntries.clear(); | |
1576 typeEntriesEnums.clear(); | |
1577 } | |
1578 | |
1579 // import for base class | |
1580 if(d_class->baseClass()) | |
1581 typeEntries << d_class->baseClass()->typeEntry(); | |
1582 | |
1583 //interfaces | |
1584 AbstractMetaClassList interfaces = d_class->interfaces(); | |
1585 if (!interfaces.isEmpty()) { | |
1586 for (int i=0; i<interfaces.size(); ++i) { | |
1587 AbstractMetaClass *iface = interfaces.at(i); | |
1588 InterfaceTypeEntry *te = (InterfaceTypeEntry*) iface->typeEntry(); | |
1589 typeEntries << te->origin(); | |
1590 } | |
1591 } | |
1592 | |
1593 AbstractMetaFunctionList d_funcs = d_class->functionsInTargetLang(); | |
1594 | |
1595 // in case of ConcreteWrapper - adding extra functions | |
1596 if (!d_class->isInterface() && d_class->isAbstract()) { | |
1597 AbstractMetaFunctionList functions_add = d_class->queryFunctions(AbstractMetaClass::NormalFunctions | AbstractMetaClass::AbstractFunctions | AbstractMetaClass::NonEmptyFunctions | AbstractMetaClass::NotRemovedFromTargetLang); | |
1598 d_funcs << functions_add; | |
1599 } | |
1600 | |
1601 for (int i=0; i<d_funcs.size(); ++i) { | |
1602 AbstractMetaFunction *function = d_funcs.at(i); | |
1603 addTypeEntry(d_class, function, typeEntries); | |
1604 } | |
1605 | |
1606 // virtual dispatch | |
1607 AbstractMetaFunctionList virtualFunctions = d_class->virtualFunctions(); | |
1608 for (int i=0; i<virtualFunctions.size(); ++i) { | |
1609 AbstractMetaFunction *function = virtualFunctions.at(i); | |
1610 addTypeEntry(d_class, function, typeEntries); | |
1611 } | |
1612 | |
1613 AbstractMetaFieldList fields = d_class->fields(); | |
1614 foreach (const AbstractMetaField *field, fields) { | |
1615 if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal())) { | |
1616 addTypeEntry(d_class, field->setter(), typeEntries); | |
1617 addTypeEntry(d_class, field->getter(), typeEntries); | |
1618 } | |
1619 } | |
1620 | |
1621 // signals | |
1622 AbstractMetaFunctionList signal_funcs = d_class->queryFunctions(AbstractMetaClass::Signals | |
1623 | AbstractMetaClass::Visible | |
1624 | AbstractMetaClass::NotRemovedFromTargetLang); | |
1625 for (int i=0; i<signal_funcs.size(); ++i) | |
1626 addTypeEntry(d_class, signal_funcs.at(i), typeEntries); | |
1627 | |
1628 if(d_class->isQObject() && d_class->name() != "QObject") | |
1629 typeEntries << TypeDatabase::instance()->findType("QObject"); | |
1630 | |
1631 if(m_recursive == 1) | |
1632 m_recursive++; | |
1633 } | |
1634 | |
1635 void DGenerator::writeImportString(QTextStream &s, const TypeEntry* typeEntry) | |
1636 { | |
1637 /* QString visibility = "private"; | |
1638 if (typeEntry->isNamespace() || typeEntry->name() == "QObject") | |
1639 visibility = "public"; | |
1640 if(d_class->baseClass() && d_class->baseClass()->typeEntry() == typeEntry) | |
1641 visibility = "public";*/ | |
1642 QString visibility = "public"; | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
1643 s << QString("%1 import ").arg(visibility) << typeEntry->javaPackage() << "." << typeEntry->targetLangName() << ";" << endl; |
1 | 1644 } |
1645 | |
1646 void DGenerator::writeRequiredImports(QTextStream &s, const AbstractMetaClass *d_class) | |
1647 { | |
1648 foreach (const TypeEntry *typeEntry, typeEntriesEnums) { | |
1649 if (!excludedTypes.contains(typeEntry->name()) && d_class->typeEntry() != typeEntry | |
1650 && typeEntry->javaQualifier() != typeEntry->name() | |
1651 /*also*/ && !excludedTypes2.contains(typeEntry->name())) | |
1652 writeImportString(s, typeEntry); | |
1653 } | |
1654 | |
1655 foreach (const TypeEntry *typeEntry, typeEntries) { | |
1656 if (!excludedTypes.contains(typeEntry->name()) && d_class->typeEntry() != typeEntry | |
1657 && typeEntry->javaQualifier() != typeEntry->name() | |
1658 /*also*/ && !excludedTypes2.contains(typeEntry->name())) | |
1659 writeImportString(s, typeEntry); | |
1660 } | |
1661 excludedTypes2.clear(); | |
1662 } | |
1663 | |
1664 void DGenerator::writeDestructor(QTextStream &s, const AbstractMetaClass *d_class) | |
1665 { | |
1666 if (!d_class->hasConstructors()) | |
1667 return; | |
1668 | |
1669 s << endl; | |
1670 if (d_class->baseClassName().isEmpty()) { | |
1671 s << INDENT << "~this() { " << endl; | |
1672 { | |
1673 Indentation indent(INDENT); | |
1674 | |
1675 if(d_class->name() == "QObject") | |
1676 s << INDENT << "if(!__gc_managed)" << endl | |
1677 << INDENT << " remove(__gc_ref_list, this);" << endl | |
1678 << INDENT << "if(!__no_real_delete && __gc_managed)" << endl | |
1679 << INDENT << " __free_native_resources();" << endl; | |
1680 else | |
1681 s << INDENT << "if(!__no_real_delete)" << endl | |
1682 << INDENT << " __free_native_resources();" << endl; | |
1683 } | |
1684 s << INDENT << "}" << endl << endl; | |
1685 } | |
1686 | |
1687 s << INDENT << "protected void __free_native_resources() {" << endl; | |
1688 { | |
1689 Indentation indent(INDENT); | |
1690 s << INDENT << "qtd_" << d_class->name() << "_destructor(nativeId());" << endl; | |
1691 } | |
1692 s << INDENT << "}" << endl << endl; | |
1693 } | |
1694 | |
1695 void DGenerator::writeOwnershipMethods(QTextStream &s, const AbstractMetaClass *d_class) | |
1696 { | |
1697 s << INDENT << "void __set_native_ownership(bool ownership_)"; | |
1698 if (d_class->isInterface() || d_class->isNamespace()) | |
1699 s << ";"; | |
1700 else { | |
1701 s << " {" << endl | |
1702 << INDENT << " __no_real_delete = ownership_;" << endl | |
1703 << INDENT << "}" << endl << endl; | |
1704 } | |
1705 } | |
1706 | |
1707 void DGenerator::writeSignalHandlers(QTextStream &s, const AbstractMetaClass *d_class) | |
1708 { | |
1709 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class); | |
1710 | |
1711 //TODO: linkage trivia should be abstracted away | |
1712 QString attr; | |
1713 | |
1714 s << "// signal handlers" << endl; | |
1715 foreach(AbstractMetaFunction *signal, signal_funcs) { | |
1716 QString sigExternName = signalExternName(d_class, signal); | |
1717 | |
1718 s << "private " << attr << "extern(C) void " << sigExternName << "_connect(void* native_id);" << endl; | |
1719 s << "private " << attr << "extern(C) void " << sigExternName << "_disconnect(void* native_id);" << endl; | |
1720 | |
1721 QString extra_args; | |
1722 | |
1723 AbstractMetaArgumentList arguments = signal->arguments(); | |
1724 foreach (AbstractMetaArgument *argument, arguments) { | |
1725 if(argument->type()->isContainer()) { | |
1726 QString arg_name = argument->indexedName(); | |
1727 const AbstractMetaType *arg_type = argument->type(); | |
1728 QString type_string = translateType(argument->type(), signal->implementingClass(), BoxedPrimitive); | |
1729 extra_args += ", " + type_string + " " + arg_name; | |
1730 } | |
1731 } | |
1732 | |
1733 s << "private extern(C) void " << sigExternName << "_handle_in_d(void* d_entity, void** args" << extra_args<< ") {" << endl; | |
1734 { | |
1735 Indentation indent(INDENT); | |
1736 s << INDENT << "auto d_object = cast(" << d_class->name() << ") d_entity;" << endl; | |
1737 int sz = arguments.count(); | |
1738 | |
1739 for (int j=0; j<sz; ++j) { | |
1740 AbstractMetaArgument *argument = arguments.at(j); | |
1741 QString arg_name = argument->indexedName(); | |
1742 AbstractMetaType *type = argument->type(); | |
1743 // if has QString argument we have to pass char* and str.length to QString constructor | |
1744 | |
1745 QString arg_ptr = QString("args[%1]").arg(argument->argumentIndex() + 1); | |
1746 | |
1747 if (type->isTargetLangString()) | |
1748 s << INDENT << "auto " << arg_name << "_ptr = " << arg_ptr << ";" << endl | |
1749 << INDENT << "string " << arg_name << " = QString.toNativeString(" << arg_name << "_ptr);"; | |
1750 else if(type->isPrimitive() || type->isEnum() || type->isFlags() || type->typeEntry()->isStructInD()) { | |
1751 QString type_name = argument->type()->typeEntry()->qualifiedTargetLangName(); | |
1752 if (type->isFlags()) | |
1753 type_name = "int"; | |
1754 s << INDENT << "auto " << arg_name << " = *(cast(" << type_name << "*)" << arg_ptr << ");"; | |
1755 } else if(type->isObject() || type->isQObject() | |
1756 || (type->typeEntry()->isValue() && type->isNativePointer()) | |
1757 || type->isValue()) { | |
1758 QString type_name = type->name(); | |
1759 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); | |
1760 if(ctype->isAbstract()) | |
1761 type_name = type_name + "_ConcreteWrapper"; | |
1762 s << INDENT << "scope " << arg_name << " = new " << type_name | |
1763 << "(cast(void*)(" << arg_ptr << "), true);" << endl | |
1764 << INDENT << arg_name << ".__no_real_delete = true;"; | |
1765 } | |
1766 s << endl; | |
1767 } | |
1768 // s << INDENT << "Stdout(\"" << d_class->name() << "\", \"" << signal->name() << "\").newline;" << endl; | |
1769 s << INDENT << "d_object." << signal->name() << ".emit("; | |
1770 for (int j = 0; j<sz; ++j) { | |
1771 AbstractMetaArgument *argument = arguments.at(j); | |
1772 QString arg_name = argument->indexedName(); | |
1773 if (j != 0) | |
1774 s << ", "; | |
1775 s << arg_name; | |
1776 } | |
1777 | |
1778 s << ");" << endl; | |
1779 } | |
1780 s << "}" << endl; | |
1781 } | |
1782 } | |
1783 | |
1784 void DGenerator::write(QTextStream &s, const AbstractMetaClass *d_class) | |
1785 { | |
1786 ReportHandler::debugSparse("Generating class: " + d_class->fullName()); | |
1787 | |
1788 bool fakeClass = d_class->attributes() & AbstractMetaAttributes::Fake; | |
1789 | |
1790 if (m_docs_enabled) { | |
1791 m_doc_parser = new DocParser(m_doc_directory + "/" + d_class->name().toLower() + ".jdoc"); | |
1792 } | |
1793 if (!m_isRecursive) | |
1794 s << "module " << d_class->package() << "." << d_class->name() <<";" << endl << endl; | |
1795 | |
39 | 1796 /* |
1 | 1797 s << "// some type info" << endl; |
1798 QString hasVirtuals = d_class->hasVirtualFunctions() ? "has" : "doesn't have"; | |
1799 QString isFinal = d_class->isFinal() ? "is" : "is not"; | |
1800 QString isNativeId = d_class->typeEntry()->isNativeIdBased() ? "is" : "is not"; | |
1801 s << "// " << hasVirtuals << " virtual functions" << endl | |
1802 << "// " << isFinal << " final" << endl | |
1803 << "// " << isNativeId << " native id based" << endl << endl | |
1804 << "// " << d_class->generateShellClass() << " shell class" << endl | |
1805 << "// " << d_class->hasVirtualFunctions() << endl | |
1806 << "// " << d_class->hasProtectedFunctions() << endl | |
1807 << "// " << d_class->hasFieldAccessors() << endl | |
1808 << "// " << d_class->typeEntry()->isObject() << endl; | |
39 | 1809 */ |
1 | 1810 |
1811 const ComplexTypeEntry *ctype = d_class->typeEntry(); | |
1812 if (!ctype->addedTo.isEmpty() && !m_isRecursive) { | |
1813 ComplexTypeEntry *ctype_parent = TypeDatabase::instance()->findComplexType(ctype->addedTo); | |
1814 s << "public import " << ctype_parent->javaPackage() << "." << ctype_parent->name() << ";" << endl; | |
1815 return; | |
1816 } | |
1817 | |
1818 if(d_class->isInterface() && !m_isRecursive) { | |
1819 s << "public import " << ctype->javaPackage() << "." << ctype->qualifiedCppName() << ";" << endl; | |
1820 return; | |
1821 } | |
1822 AbstractMetaClassList includedClassesList; | |
1823 | |
1824 /* m_recursive is increasing by 1 each time we fill the import for a class | |
1825 if it equals to 0 or 1 imports Set is cleared before a filling cycle - if there | |
1826 is only one class as usual or if there are many classes in module, but before | |
1827 filling for first class we need to clear Set. Wow :) | |
1828 */ | |
1829 if(ctype->includedClasses.size() > 0) | |
1830 m_recursive = 1; | |
1831 else | |
1832 m_recursive = 0; | |
1833 | |
1834 foreach(QString child, ctype->includedClasses) { | |
1835 ComplexTypeEntry *ctype_child = TypeDatabase::instance()->findComplexType(child); | |
1836 foreach (AbstractMetaClass *cls, m_classes) { | |
1837 if ( cls->name() == ctype_child->name() ) { | |
1838 includedClassesList << cls; | |
1839 fillRequiredImports(cls); | |
1840 excludedTypes2 << cls->name(); | |
1841 } | |
1842 } | |
1843 } | |
1844 | |
1845 QString interface; | |
1846 if(d_class->typeEntry()->designatedInterface()) | |
1847 interface = d_class->typeEntry()->designatedInterface()->name(); | |
1848 | |
1849 if(d_class->typeEntry()->designatedInterface()) { | |
1850 foreach (AbstractMetaClass *cls, m_classes) { | |
1851 if ( cls->name() == interface ) { | |
1852 includedClassesList << cls; | |
1853 fillRequiredImports(cls); | |
1854 excludedTypes2 << cls->name(); | |
1855 } | |
1856 } | |
1857 } | |
1858 | |
1859 fillRequiredImports(d_class); | |
1860 excludedTypes2 << d_class->name(); | |
1861 if(ctype->includedClasses.size() > 0) | |
1862 m_recursive = 0; | |
1863 | |
1864 QList<Include> includes = d_class->typeEntry()->extraIncludes(); | |
1865 foreach (const Include &inc, includes) { | |
1866 if (inc.type == Include::TargetLangImport) { | |
1867 s << inc.toString() << endl; | |
1868 } | |
1869 } | |
1870 | |
1871 if (!m_isRecursive) { | |
1872 s << "public import qt.QGlobal;" << endl | |
1873 << "public import qt.core.Qt;" << endl | |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
39
diff
changeset
|
1874 << "private import qt.QtDObject;" << endl |
81 | 1875 << "private import qt.core.QString;" << endl |
1876 << "private import qt.qtd.Array;" << endl; | |
1 | 1877 if (d_class->isQObject()) { |
1878 s << "public import qt.Signal;" << endl; | |
1879 if (d_class->name() != "QObject") | |
1880 s << "public import qt.core.QObject;" << endl; | |
1881 } | |
1882 | |
1883 // qtd2 hack! | |
1884 if (d_class->name() == "QCoreApplication") | |
1885 s << "private import qt.core.ArrayOps;" << endl; | |
1886 else if (d_class->name() == "QApplication") | |
1887 s << "private import qt.gui.ArrayOps;" << endl; | |
1888 | |
1889 if (!d_class->enums().isEmpty()) | |
1890 s << "public import " << d_class->package() << "." << d_class->name() << "_enum;" << endl << endl; | |
1891 | |
1892 s << "// automatic imports-------------" << endl; | |
1893 writeRequiredImports(s, d_class); | |
1894 s << endl; | |
1895 if (dPhobos) | |
1896 { | |
1897 s << "import std.stdio;" << endl | |
1898 << "import std.string;" << endl | |
1899 << "import std.utf;" << endl | |
1900 << "import core.memory;"; | |
1901 } | |
1902 else | |
1903 { | |
1904 s << "import tango.io.Stdout;" << endl | |
1905 << "import tango.stdc.stringz;" << endl | |
1906 << "import tango.text.convert.Utf;" << endl | |
1907 << "import tango.core.Memory;"; | |
1908 } | |
1909 s << endl << endl << endl; | |
1910 } | |
1911 | |
1912 if (m_doc_parser) { | |
1913 s << m_doc_parser->documentation(d_class) << endl << endl; | |
1914 } | |
1915 | |
1916 /* qtd s << "@QtJambiGeneratedClass" << endl; | |
1917 | |
1918 if ((d_class->typeEntry()->typeFlags() & ComplexTypeEntry::Deprecated) != 0) { | |
1919 s << "@Deprecated" << endl; | |
1920 } | |
1921 */ | |
1922 | |
1923 // Enums aliases outside of the class - hack | |
1924 if (!d_class->enums().isEmpty()) { | |
1925 QString fileName = QString("%1_enum.d").arg(d_class->name()); | |
1926 FileOut fileOut(outputDirectory() + "/" + subDirectoryForClass(d_class) + "/" + fileName); | |
1927 | |
1928 fileOut.stream << "module " << d_class->package() << "." << d_class->name() << "_enum;" << endl << endl; | |
1929 foreach (AbstractMetaEnum *d_enum, d_class->enums()) | |
1930 writeEnum(fileOut.stream, d_enum); | |
1931 } | |
1932 | |
1933 | |
1934 s << endl; | |
1935 | |
1936 if (d_class->isInterface()) { | |
1937 s << "public interface "; | |
1938 } else { | |
1939 if (d_class->isPublic()) | |
1940 s << "public "; | |
1941 // else friendly | |
1942 | |
1943 bool force_abstract = (d_class->typeEntry()->typeFlags() & ComplexTypeEntry::ForceAbstract) != 0; | |
1944 if (d_class->isFinal() && !force_abstract) | |
1945 s << "final "; | |
1946 if ((d_class->isAbstract() && !d_class->isNamespace()) || force_abstract) | |
1947 s << "abstract "; | |
1948 | |
1949 if (!d_class->typeEntry()->targetType().isEmpty()) { | |
1950 s << d_class->typeEntry()->targetType() << " "; | |
1951 } else if (d_class->isNamespace() && d_class->functionsInTargetLang().size() == 0) { | |
1952 s << "interface "; | |
1953 } else if (d_class->isNamespace()) { | |
1954 s << "class "; | |
1955 } else { | |
1956 s << "class "; | |
1957 } | |
1958 | |
1959 } | |
1960 | |
1961 const ComplexTypeEntry *type = d_class->typeEntry(); | |
1962 | |
1963 s << d_class->name(); | |
1964 | |
1965 if (type->isGenericClass()) { | |
1966 s << "<"; | |
1967 QList<TypeEntry *> templateArguments = d_class->templateBaseClass()->templateArguments(); | |
1968 for (int i=0; i<templateArguments.size(); ++i) { | |
1969 TypeEntry *templateArgument = templateArguments.at(i); | |
1970 if (i > 0) | |
1971 s << ", "; | |
1972 s << templateArgument->name(); | |
1973 } | |
1974 s << ">"; | |
1975 } | |
1976 | |
1977 if (!d_class->isNamespace() && !d_class->isInterface()) { | |
1978 if (!d_class->baseClassName().isEmpty()) { | |
1979 s << " : " << d_class->baseClass()->name(); | |
1980 } else { | |
1981 QString sc = type->defaultSuperclass(); | |
1982 if ((sc != d_class->name()) && !sc.isEmpty()) | |
1983 s << " : " << sc; | |
1984 } | |
1985 }/* qtd else if (d_class->isInterface()) { | |
1986 s << " extends QtJambiInterface"; | |
1987 }*/ | |
1988 | |
1989 // implementing interfaces... | |
1990 bool implements = false; | |
1991 AbstractMetaClassList interfaces = d_class->interfaces(); | |
1992 if (!interfaces.isEmpty()) { | |
1993 if (!d_class->isInterface()) | |
1994 s << ", "; | |
1995 else { | |
1996 implements = true; | |
1997 s << ": "; | |
1998 } | |
1999 for (int i=0; i<interfaces.size(); ++i) { | |
2000 AbstractMetaClass *iface = interfaces.at(i); | |
2001 if (i) s << ", "; | |
2002 s << iface->name(); | |
2003 } | |
2004 } | |
2005 /* qtd | |
2006 if (isComparable(d_class)) { | |
2007 if (!implements) { | |
2008 implements = true; | |
2009 s << endl << " implements "; | |
2010 } | |
2011 else | |
2012 s << "," << endl << " "; | |
2013 s << "java.lang.Comparable<Object>"; | |
2014 } | |
2015 | |
2016 if (d_class->hasCloneOperator()) { | |
2017 if (!implements) { | |
2018 implements = true; | |
2019 s << endl << " implements "; | |
2020 } | |
2021 else | |
2022 s << "," << endl << " "; | |
2023 s << "java.lang.Cloneable"; | |
2024 } | |
2025 */ | |
2026 s << endl << "{" << endl; | |
2027 | |
2028 Indentation indent(INDENT); | |
2029 | |
2030 // Define variables for reference count mechanism | |
2031 if (!d_class->isInterface() && !d_class->isNamespace()) { | |
2032 QHash<QString, int> variables; | |
2033 foreach (AbstractMetaFunction *function, d_class->functions()) { | |
2034 QList<ReferenceCount> referenceCounts = function->referenceCounts(d_class); | |
2035 foreach (ReferenceCount refCount, referenceCounts) { | |
2036 variables[refCount.variableName] |= refCount.action | |
2037 | refCount.access | |
2038 | (refCount.threadSafe ? ReferenceCount::ThreadSafe : 0) | |
2039 | (function->isStatic() ? ReferenceCount::Static : 0) | |
2040 | (refCount.declareVariable.isEmpty() ? ReferenceCount::DeclareVariable : 0); | |
2041 } | |
2042 } | |
2043 | |
2044 foreach (QString variableName, variables.keys()) { | |
2045 int actions = variables.value(variableName) & ReferenceCount::ActionsMask; | |
2046 // bool threadSafe = variables.value(variableName) & ReferenceCount::ThreadSafe; | |
2047 bool isStatic = variables.value(variableName) & ReferenceCount::Static; | |
2048 bool declareVariable = variables.value(variableName) & ReferenceCount::DeclareVariable; | |
2049 int access = variables.value(variableName) & ReferenceCount::AccessMask; | |
2050 | |
2051 if (actions == ReferenceCount::Ignore || !declareVariable) | |
2052 continue; | |
2053 | |
2054 if (((actions & ReferenceCount::Add) == 0) != ((actions & ReferenceCount::Remove) == 0)) { | |
2055 QString warn = QString("either add or remove specified for reference count variable '%1' in '%2' but not both") | |
2056 .arg(variableName).arg(d_class->fullName()); | |
2057 ReportHandler::warning(warn); | |
2058 } | |
2059 s << endl; | |
2060 /* qtd | |
2061 if (TypeDatabase::instance()->includeEclipseWarnings()) | |
2062 s << INDENT << "@SuppressWarnings(\"unused\")" << endl; | |
2063 */ | |
2064 if (actions != ReferenceCount::Set && actions != ReferenceCount::Ignore) { // qtd2 | |
2065 | |
2066 s << INDENT; | |
2067 switch (access) { | |
2068 case ReferenceCount::Private: | |
2069 s << "package "; break; // qtd | |
2070 case ReferenceCount::Protected: | |
2071 s << "protected "; break; | |
2072 case ReferenceCount::Public: | |
2073 s << "public "; break; | |
2074 default: | |
2075 s << "protected"; // friendly | |
2076 } | |
2077 | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
2078 } // qtd2 |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
2079 |
1 | 2080 if (isStatic) |
2081 s << "static "; | |
2082 | |
2083 if (actions != ReferenceCount::Set && actions != ReferenceCount::Ignore) { | |
2084 s << "Object[] " << variableName << ";" << endl; | |
2085 /* | |
2086 if (threadSafe) | |
2087 s << "java.util.Collections.synchronizedCollection("; | |
2088 s << "new java.util.ArrayList<Object>()"; | |
2089 if (threadSafe) | |
2090 s << ")"; | |
2091 s << ";" << endl;*/ | |
2092 } else if (actions != ReferenceCount::Ignore) { | |
2093 /* qtd2 if (threadSafe) | |
2094 s << "synchronized ";*/ | |
2095 s << "Object " << variableName << " = null;" << endl; | |
2096 } | |
2097 } | |
2098 s << endl; | |
2099 } | |
2100 | |
2101 /* qtd2 | |
2102 if (!d_class->isInterface() && (!d_class->isNamespace() || d_class->functionsInTargetLang().size() > 0) | |
2103 && (d_class->baseClass() == 0 || d_class->package() != d_class->baseClass()->package())) { | |
2104 s << endl | |
2105 << INDENT << "static {" << endl; | |
2106 | |
2107 if (d_class->isNamespace()) { | |
2108 s << INDENT << " qt.QtJambi_LibraryInitializer.init();" << endl; | |
2109 } | |
2110 | |
2111 s << INDENT << " " << d_class->package() << ".QtJambi_LibraryInitializer.init();" << endl | |
2112 << INDENT << "}" << endl; | |
2113 } | |
2114 */ | |
2115 | |
2116 // Enums aliaases | |
2117 foreach (AbstractMetaEnum *d_enum, d_class->enums()) | |
2118 writeEnumAlias(s, d_enum); | |
2119 | |
2120 if (!d_class->enums().isEmpty() && !d_class->functions().isEmpty()) | |
2121 s << endl; | |
2122 | |
2123 // Signals | |
2124 AbstractMetaFunctionList signal_funcs; | |
2125 | |
2126 signal_funcs = signalFunctions(d_class); | |
2127 if (signal_funcs.size()) | |
2128 { | |
2129 writeSignalConnectors(s, d_class, signal_funcs); | |
2130 foreach (AbstractMetaFunction *signal, signal_funcs) | |
2131 { | |
2132 if (d_class == signal->implementingClass()) | |
2133 writeSignal(s, signal); | |
2134 } | |
2135 } | |
2136 | |
2137 // Class has subclasses but also only private constructors | |
2138 if (!d_class->isFinalInTargetLang() && d_class->isFinalInCpp()) { | |
2139 s << endl << INDENT << "/**" << endl | |
2140 << INDENT << " * This constructor is a place holder intended to prevent" << endl | |
2141 << INDENT << " * users from subclassing the class. Certain classes can" << endl | |
2142 << INDENT << " * unfortunately only be subclasses internally. The constructor" << endl | |
2143 << INDENT << " * will indiscriminately throw an exception if called. If the" << endl | |
2144 << INDENT << " * exception is ignored, any use of the constructed object will" << endl | |
2145 << INDENT << " * cause an exception to occur." << endl << endl | |
2146 << INDENT << " * @throws QClassCannotBeSubclassedException" << endl | |
2147 << INDENT << " **/" << endl | |
2148 << INDENT << "protected " << d_class->name() << "() throws QClassCannotBeSubclassedException {" << endl | |
2149 << INDENT << " throw new QClassCannotBeSubclassedException(" << d_class->name() << ".class);" << endl | |
2150 << INDENT << "}" << endl << endl; | |
2151 } | |
2152 s << "// Functions" << endl; | |
2153 | |
2154 // Functions | |
2155 AbstractMetaFunctionList d_funcs = d_class->functionsInTargetLang(); | |
2156 for (int i=0; i<d_funcs.size(); ++i) { | |
2157 AbstractMetaFunction *function = d_funcs.at(i); | |
2158 | |
2159 // If a method in an interface class is modified to be private, this should | |
2160 // not be present in the interface at all, only in the implementation. | |
2161 if (d_class->isInterface()) { | |
2162 uint includedAttributes = 0; | |
2163 uint excludedAttributes = 0; | |
2164 retrieveModifications(function, d_class, &excludedAttributes, &includedAttributes); | |
2165 if (includedAttributes & AbstractMetaAttributes::Private) | |
2166 continue; | |
2167 } | |
2168 | |
2169 if (!notWrappedYet(function)) // qtd2 | |
2170 writeFunction(s, function); | |
2171 // s << function->minimalSignature() << endl; | |
2172 } | |
2173 if(d_class->isInterface()) | |
2174 s << endl << INDENT << "public void* __ptr_" << d_class->name() << "();" << endl << endl; | |
2175 | |
2176 | |
2177 s << "// Field accessors" << endl; | |
2178 // Field accessors | |
2179 AbstractMetaFieldList fields = d_class->fields(); | |
2180 foreach (const AbstractMetaField *field, fields) { | |
2181 if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal())) | |
2182 writeFieldAccessors(s, field); | |
2183 } | |
2184 | |
2185 /* qtd | |
2186 | |
2187 // the static fromNativePointer function... | |
2188 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) { | |
2189 s << endl | |
2190 << INDENT << "public static native " << d_class->name() << " fromNativePointer(" | |
2191 << "QNativePointer nativePointer);" << endl; | |
2192 } | |
2193 | |
2194 if (d_class->isQObject()) { | |
2195 s << endl; | |
2196 if (TypeDatabase::instance()->includeEclipseWarnings()) | |
2197 s << INDENT << "@SuppressWarnings(\"unused\")" << endl; | |
2198 | |
2199 s << INDENT << "private static native long originalMetaObject();" << endl; | |
2200 } | |
2201 | |
2202 // The __qt_signalInitialization() function | |
2203 if (signal_funcs.size() > 0) { | |
2204 s << endl | |
2205 << INDENT << "@Override" << endl | |
2206 << INDENT << "@QtBlockedSlot protected boolean __qt_signalInitialization(String name) {" << endl | |
2207 << INDENT << " return (__qt_signalInitialization(nativeId(), name)" << endl | |
2208 << INDENT << " || super.__qt_signalInitialization(name));" << endl | |
2209 << INDENT << "}" << endl | |
2210 << endl | |
2211 << INDENT << "@QtBlockedSlot" << endl | |
2212 << INDENT << "private native boolean __qt_signalInitialization(long ptr, String name);" << endl; | |
2213 } | |
2214 */ | |
2215 // Add dummy constructor for use when constructing subclasses | |
2216 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) { | |
2217 s << endl | |
2218 << INDENT << "public " | |
2219 << "this"; | |
2220 | |
2221 if(d_class->name() == "QObject") | |
2222 { | |
2223 { | |
2224 Indentation indent(INDENT); | |
2225 s << "(void* native_id, bool gc_managed) {" << endl | |
2226 << INDENT << "if(!gc_managed)" << endl | |
2227 << INDENT << " __gc_ref_list ~= this;" << endl | |
2228 << INDENT << "__gc_managed = gc_managed;" << endl | |
2229 << INDENT << "super(native_id);" << endl; | |
2230 } | |
2231 } | |
2232 else { | |
2233 Indentation indent(INDENT); | |
2234 if(d_class->isQObject()) | |
2235 s << "(void* native_id, bool gc_managed) {" << endl | |
2236 << INDENT << "super(native_id, gc_managed);" << endl; | |
2237 else | |
2238 s << "(void* native_id, bool no_real_delete = false) {" << endl | |
2239 << INDENT << "super(native_id, no_real_delete);" << endl; | |
2240 } | |
2241 | |
2242 // customized store-result instances | |
2243 d_funcs = d_class->functionsInTargetLang(); | |
2244 for (int i=0; i<d_funcs.size(); ++i) { | |
2245 AbstractMetaFunction *d_function = d_funcs.at(i); | |
2246 uint included_attributes = 0; | |
2247 uint excluded_attributes = 0; | |
2248 setupForFunction(d_function, &included_attributes, &excluded_attributes); | |
2249 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes; | |
2250 bool isStatic = (attr & AbstractMetaAttributes::Static); | |
2251 | |
2252 if (!isStatic && (attr & AbstractMetaAttributes::Abstract)) | |
2253 continue; | |
2254 | |
2255 if(d_function->storeResult()) { | |
2256 QString type_name = d_function->type()->name(); | |
2257 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry()); | |
2258 if(ctype->isAbstract()) | |
2259 type_name = type_name + "_ConcreteWrapper"; | |
2260 | |
2261 s << INDENT << " __m_" << d_function->name() << " = new " | |
2262 << type_name << "(cast(void*)null);" << endl; | |
2263 if (d_function->type()->isQObject()) | |
2264 s << INDENT << " __m_" << d_function->name() << ".__no_real_delete = true;" << endl; | |
2265 } | |
2266 } | |
2267 | |
2268 // pointers to native interface objects for classes that implement interfaces | |
2269 // initializing | |
2270 interfaces = d_class->interfaces(); | |
2271 if (!interfaces.isEmpty()) { | |
2272 for (int i=0; i<interfaces.size(); ++i) { | |
2273 AbstractMetaClass *iface = interfaces.at(i); | |
2274 | |
2275 s << INDENT << " __m_ptr_" << iface->name() << " = qtd_" << d_class->name() << "_cast_to_" << iface->qualifiedCppName() | |
2276 << "(nativeId);" << endl; | |
2277 } | |
2278 } | |
2279 | |
2280 | |
2281 s << INDENT << "}" << endl << endl; | |
2282 | |
2283 /******************!!!DUBLICATE OF ABOVE!!!*********************/ | |
2284 for (int i=0; i<d_funcs.size(); ++i) { | |
2285 AbstractMetaFunction *d_function = d_funcs.at(i); | |
2286 uint included_attributes = 0; | |
2287 uint excluded_attributes = 0; | |
2288 setupForFunction(d_function, &included_attributes, &excluded_attributes); | |
2289 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes; | |
2290 bool isStatic = (attr & AbstractMetaAttributes::Static); | |
2291 | |
2292 if (!isStatic && (attr & AbstractMetaAttributes::Abstract)) | |
2293 continue; | |
2294 | |
2295 if(d_function->storeResult()) { | |
2296 QString type_name = d_function->type()->name(); | |
2297 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry()); | |
2298 if(ctype->isAbstract()) | |
2299 type_name = type_name + "_ConcreteWrapper"; | |
2300 | |
2301 s << INDENT << type_name << " __m_" << d_function->name() << ";" << endl; | |
2302 } | |
2303 } | |
2304 /***************************************************************/ | |
2305 | |
2306 // pointers to native interface objects for classes that implement interfaces | |
2307 // initializing | |
2308 interfaces = d_class->interfaces(); | |
2309 if (!interfaces.isEmpty()) { | |
2310 for (int i=0; i<interfaces.size(); ++i) { | |
2311 AbstractMetaClass *iface = interfaces.at(i); | |
2312 | |
2313 s << INDENT << "private void* __m_ptr_" << iface->name() << ";" << endl | |
2314 << INDENT << "public void* __ptr_" << iface->name() << "() { return __m_ptr_" << iface->name() << "; }" << endl << endl; | |
2315 } | |
2316 } | |
2317 | |
2318 writeDestructor(s, d_class); | |
2319 } | |
2320 | |
2321 /* qtd | |
2322 // Add a function that converts an array of the value type to a QNativePointer | |
2323 if (d_class->typeEntry()->isValue() && !fakeClass) { | |
2324 s << endl | |
2325 << INDENT << "public static native QNativePointer nativePointerArray(" << d_class->name() | |
2326 << " array[]);" << endl; | |
2327 } | |
2328 | |
2329 // write the cast to this function.... | |
2330 if (d_class->isInterface()) { | |
2331 s << endl | |
2332 << " public long __qt_cast_to_" | |
2333 << static_cast<const InterfaceTypeEntry *>(type)->origin()->targetLangName() | |
2334 << "(long ptr);" << endl; | |
2335 } else { | |
2336 foreach (AbstractMetaClass *cls, interfaces) { | |
2337 s << endl | |
2338 << " @QtBlockedSlot public native long __qt_cast_to_" | |
2339 << static_cast<const InterfaceTypeEntry *>(cls->typeEntry())->origin()->targetLangName() | |
2340 << "(long ptr);" << endl; | |
2341 } | |
2342 } | |
2343 */ | |
2344 | |
2345 /* qtd writeJavaLangObjectOverrideFunctions(s, d_class); | |
2346 */ | |
2347 writeOwnershipMethods(s, d_class); | |
2348 s << "// Injected code in class" << endl; | |
2349 writeExtraFunctions(s, d_class); | |
2350 // qtd2 writeToStringFunction(s, d_class); | |
2351 /* qtd | |
2352 if (d_class->hasCloneOperator()) { | |
2353 writeCloneFunction(s, d_class); | |
2354 } | |
2355 */ | |
2356 s << "}" << endl; | |
2357 | |
81 | 2358 /* ---------------- injected free code ----------------*/ |
2359 const ComplexTypeEntry *class_type = d_class->typeEntry(); | |
2360 Q_ASSERT(class_type); | |
2361 | |
2362 CodeSnipList code_snips = class_type->codeSnips(); | |
2363 foreach (const CodeSnip &snip, code_snips) { | |
2364 if (!d_class->isInterface() && snip.language == TypeSystem::TargetLangFreeCode) { | |
2365 s << endl; | |
2366 snip.formattedCode(s, INDENT); | |
2367 } | |
2368 } | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2369 /* --------------------------------------------------- */ |
14 | 2370 |
1 | 2371 interfaces = d_class->interfaces(); |
2372 if (!interfaces.isEmpty()) { | |
2373 for (int i=0; i<interfaces.size(); ++i) { | |
2374 AbstractMetaClass *iface = interfaces.at(i); | |
2375 | |
2376 s << INDENT << "private static extern (C) void*" << "qtd_" << d_class->name() << "_cast_to_" << iface->qualifiedCppName() | |
2377 << "(void* nativeId);" << endl; | |
2378 } | |
2379 } | |
2380 | |
2381 if (!d_class->isInterface() && d_class->isAbstract()) { | |
2382 s << endl; | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2383 |
1 | 2384 s << INDENT << "public class " << d_class->name() << "_ConcreteWrapper : " << d_class->name() << " {" << endl; |
2385 | |
2386 { | |
2387 Indentation indent(INDENT); | |
2388 s << INDENT << "public this(void* native_id, bool no_real_delete = true) {" << endl | |
2389 << INDENT << " super(native_id, no_real_delete);" << endl; | |
2390 | |
2391 | |
2392 | |
2393 | |
2394 /******************!!!DUBLICATE!!!*********************/ | |
2395 d_funcs = d_class->functionsInTargetLang(); | |
2396 for (int i=0; i<d_funcs.size(); ++i) { | |
2397 AbstractMetaFunction *d_function = d_funcs.at(i); | |
2398 uint included_attributes = 0; | |
2399 uint excluded_attributes = 0; | |
2400 setupForFunction(d_function, &included_attributes, &excluded_attributes); | |
2401 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes; | |
2402 // qtd bool isStatic = (attr & AbstractMetaAttributes::Static); | |
2403 | |
2404 if(d_function->storeResult()) { | |
2405 QString type_name = d_function->type()->name(); | |
2406 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry()); | |
2407 if(ctype->isAbstract()) | |
2408 type_name = type_name + "_ConcreteWrapper"; | |
2409 s << INDENT << " __m_" << d_function->name() << " = new " | |
2410 << type_name << "(cast(void*)null);" << endl; | |
2411 if (d_function->type()->isQObject()) | |
2412 s << INDENT << " __m_" << d_function->name() << ".__no_real_delete = true;" << endl; | |
2413 } | |
2414 } | |
2415 | |
2416 s << INDENT << "}" << endl << endl; | |
2417 | |
2418 for (int i=0; i<d_funcs.size(); ++i) { | |
2419 AbstractMetaFunction *d_function = d_funcs.at(i); | |
2420 uint included_attributes = 0; | |
2421 uint excluded_attributes = 0; | |
2422 setupForFunction(d_function, &included_attributes, &excluded_attributes); | |
2423 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes; | |
2424 // qtd bool isStatic = (attr & AbstractMetaAttributes::Static); | |
2425 | |
2426 if(d_function->storeResult()) { | |
2427 QString type_name = d_function->type()->name(); | |
2428 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry()); | |
2429 if(ctype->isAbstract()) | |
2430 type_name = type_name + "_ConcreteWrapper"; | |
2431 | |
2432 s << INDENT << d_function->type()->name() << " __m_" << d_function->name() << ";" << endl; | |
2433 } | |
2434 } | |
2435 /***************************************************************/ | |
2436 | |
2437 | |
2438 | |
2439 | |
2440 | |
2441 | |
2442 uint exclude_attributes = AbstractMetaAttributes::Native | AbstractMetaAttributes::Abstract; | |
2443 uint include_attributes = 0; | |
2444 AbstractMetaFunctionList functions = d_class->queryFunctions(AbstractMetaClass::NormalFunctions | AbstractMetaClass::AbstractFunctions | AbstractMetaClass::NonEmptyFunctions | AbstractMetaClass::NotRemovedFromTargetLang); | |
2445 foreach (const AbstractMetaFunction *d_function, functions) { | |
2446 retrieveModifications(d_function, d_class, &exclude_attributes, &include_attributes); | |
2447 if (notWrappedYet(d_function)) | |
2448 continue; | |
2449 /* qtd s << endl | |
2450 << INDENT << "@Override" << endl; */ | |
2451 writeFunctionAttributes(s, d_function, include_attributes, exclude_attributes, | |
2452 d_function->isNormal() || d_function->isSignal() ? 0 : SkipReturnType); | |
2453 | |
2454 s << d_function->name() << "("; | |
2455 writeFunctionArguments(s, d_function, d_function->arguments().count()); | |
2456 s << ") {" << endl; | |
2457 { | |
2458 Indentation indent(INDENT); | |
2459 writeJavaCallThroughContents(s, d_function, SuperCall); | |
2460 } | |
2461 s << INDENT << "}" << endl; | |
2462 } | |
2463 } | |
2464 s << INDENT << "}" << endl << endl; | |
2465 } | |
2466 | |
2467 if (d_class->generateShellClass()) { // qtd2 | |
2468 if (d_class->hasVirtualFunctions() | |
2469 && (d_class->typeEntry()->isObject() || d_class->typeEntry()->isQObject()) ) | |
2470 s << endl << "extern (C) void *__" << d_class->name() << "_entity(void *q_ptr);" << endl << endl; | |
2471 } | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2472 |
110 | 2473 if (d_class->isQObject()) |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2474 writeQObjectFunctions(s, d_class); |
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2475 |
110 | 2476 |
2477 if (d_class->needsConversionFunc) | |
2478 writeConversionFunction(s, d_class); | |
1 | 2479 |
2480 if (d_class->hasConstructors()) | |
2481 s << "extern (C) void qtd_" << d_class->name() << "_destructor(void *ptr);" << endl << endl; | |
2482 | |
2483 // qtd | |
2484 s << endl << "// C wrappers" << endl; | |
2485 d_funcs = d_class->functionsInTargetLang(); | |
2486 if (!d_class->isInterface()) | |
2487 for (int i=0; i<d_funcs.size(); ++i) { | |
2488 AbstractMetaFunction *function = d_funcs.at(i); | |
2489 | |
2490 if (!notWrappedYet(function)) // qtd2 | |
2491 if (function->jumpTableId() == -1) | |
2492 writePrivateNativeFunction(s, function); | |
2493 } | |
2494 | |
2495 | |
2496 s << "// Just the private functions for abstract functions implemeneted in superclasses" << endl; | |
2497 // Just the private functions for abstract functions implemeneted in superclasses | |
2498 if (!d_class->isInterface() && d_class->isAbstract()) { | |
2499 d_funcs = d_class->queryFunctions(AbstractMetaClass::NormalFunctions | AbstractMetaClass::AbstractFunctions | AbstractMetaClass::NotRemovedFromTargetLang); | |
2500 foreach (AbstractMetaFunction *d_function, d_funcs) { | |
2501 if (d_function->implementingClass() != d_class) { | |
2502 s << endl; | |
2503 writePrivateNativeFunction(s, d_function); | |
2504 } | |
2505 } | |
2506 } | |
2507 | |
2508 | |
2509 foreach (const AbstractMetaField *field, fields) { | |
2510 if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal())) | |
2511 writeNativeField(s, field); | |
2512 } | |
2513 s << endl << endl; | |
2514 | |
2515 // qtd | |
2516 s << endl << "// Virtual Dispatch functions" << endl; | |
2517 AbstractMetaFunctionList virtualFunctions = d_class->virtualFunctions(); | |
2518 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { | |
2519 const AbstractMetaFunction *function = virtualFunctions.at(pos); | |
2520 if (!notWrappedYet(function)) // qtd2 | |
2521 writeShellVirtualFunction(s, function, d_class, pos); | |
2522 } | |
2523 | |
2524 //init callbacks from dll to D side | |
2525 if (cpp_shared) { | |
2526 bool shellClass = d_class->generateShellClass(); | |
2527 if (shellClass && !d_class->isInterface()) { | |
2528 QString initArgs = "void* virtuals"; | |
2529 if (d_class->isQObject()) | |
2530 initArgs += ", void* signals, void* qobj_del"; | |
2531 | |
2532 s << "private extern (C) void qtd_" << d_class->name() | |
2533 << QString("_initCallBacks(%1);").arg(initArgs) << endl << endl | |
2534 << "private bool init_flag_" << d_class->name() << " = false;" << endl | |
2535 << "void static_init_" << d_class->name() << "() {" << endl | |
2536 << INDENT << "init_flag_" << d_class->name() << " = true;" << endl << endl | |
2537 | |
2538 // virtual functions | |
2539 << INDENT << "void*[" << virtualFunctions.size() << "] virt_arr;" << endl; | |
2540 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { | |
2541 const AbstractMetaFunction *function = virtualFunctions.at(pos); | |
2542 if (!notWrappedYet(function)) // qtd2 | |
2543 s << INDENT << "virt_arr[" << pos << "] = &" << function->marshalledName() << "_dispatch;" <<endl; | |
2544 } | |
2545 if (virtualFunctions.size() == 0) | |
2546 initArgs = "null"; | |
2547 else | |
2548 initArgs = "virt_arr.ptr"; | |
2549 | |
2550 // signals | |
2551 if (d_class->isQObject()) { | |
2552 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class); | |
2553 s << endl << INDENT << "void*[" << signal_funcs.size() << "] sign_arr;" << endl; | |
2554 for(int i = 0; i < signal_funcs.size(); i++) { | |
2555 AbstractMetaFunction *signal = signal_funcs.at(i); | |
2556 s << INDENT << "sign_arr[" << i << "] = &" << signalExternName(d_class, signal) << "_handle_in_d;" << endl; | |
2557 } | |
2558 if(signal_funcs.size() == 0) | |
2559 initArgs += ", null"; | |
2560 else | |
2561 initArgs += ", sign_arr.ptr"; | |
2562 | |
2563 // QObject_delete | |
2564 s << endl << INDENT << "void *qobj_del;" << endl | |
2565 << INDENT << "qobj_del = &qtd_D_" << d_class->name() << "_delete;" << endl; | |
2566 initArgs += ", qobj_del"; | |
2567 } | |
2568 | |
2569 s << INDENT << "qtd_" << d_class->name() << QString("_initCallBacks(%1);").arg(initArgs) << endl | |
2570 << "}" << endl << endl; | |
2571 } | |
2572 } | |
2573 | |
2574 writeSignalHandlers(s, d_class); | |
2575 s << endl; | |
2576 | |
2577 if (m_docs_enabled) { | |
2578 delete m_doc_parser; | |
2579 m_doc_parser = 0; | |
2580 } | |
2581 | |
2582 // qtd multiple classes | |
2583 foreach (AbstractMetaClass *cls, includedClassesList) { | |
2584 m_isRecursive = true; | |
2585 write(s, cls); | |
2586 m_isRecursive = false; | |
2587 } | |
2588 } | |
2589 | |
110 | 2590 void DGenerator::writeConversionFunction(QTextStream &s, const AbstractMetaClass *d_class) |
2591 { | |
2592 const ComplexTypeEntry *ctype = d_class->typeEntry(); | |
2593 QString class_name = ctype->name(); | |
111 | 2594 QString return_type_name = class_name; |
2595 if(ctype->designatedInterface()) | |
2596 return_type_name = ctype->designatedInterface()->name(); | |
2597 s << return_type_name << " qtd_" << class_name << "_from_ptr(void* __qt_return_value) {" << endl; | |
110 | 2598 |
2599 if(ctype->isQObject()) { | |
2600 QString type_name = class_name; | |
2601 if(ctype->isAbstract()) | |
2602 type_name = type_name + "_ConcreteWrapper"; | |
2603 | |
2604 s << INDENT << "if (__qt_return_value is null)" << endl | |
2605 << INDENT << " return null;" << endl | |
2606 << INDENT << "void* d_obj = qtd_" << class_name << "_d_pointer(__qt_return_value);" << endl | |
2607 << INDENT << "if (d_obj is null) {" << endl | |
2608 << INDENT << " auto new_obj = new " << type_name << "(__qt_return_value, true);" << endl | |
2609 << INDENT << " qtd_" << class_name << "_create_link(new_obj.nativeId, cast(void*) new_obj);" << endl | |
2610 << INDENT << " new_obj.__no_real_delete = true;" << endl | |
2611 << INDENT << " return new_obj;" << endl | |
2612 << INDENT << "} else" << endl | |
2613 << INDENT << " return cast(" << class_name << ") d_obj;" << endl; | |
111 | 2614 } else if (ctype->isObject()) { |
110 | 2615 QString type_name = class_name; |
2616 if(ctype->isAbstract()) | |
2617 type_name = type_name + "_ConcreteWrapper"; | |
2618 | |
2619 // if class has virtual functions then it has classname_entity function so | |
2620 // we can look for D Object pointer. otherwise create new wrapper | |
2621 if (d_class->hasVirtualFunctions()) { | |
2622 s << INDENT << "void* d_obj = __" << ctype->name() << "_entity(__qt_return_value);" << endl | |
2623 << INDENT << "if (d_obj !is null) {" << endl | |
2624 << INDENT << " auto d_obj_ref = cast (Object) d_obj;" << endl | |
2625 << INDENT << " return cast(" << return_type_name << ") d_obj_ref;" << endl | |
2626 << INDENT << "} else {" << endl | |
2627 << INDENT << " auto return_value = new " << type_name << "(__qt_return_value, true);" << endl | |
2628 << INDENT << " return_value.__no_real_delete = true;" << endl | |
2629 << INDENT << " return return_value;" << endl | |
2630 << INDENT << "}"; | |
2631 } else { | |
2632 s << INDENT << "auto return_value = new " << type_name << "(__qt_return_value, true);" << endl | |
2633 << INDENT << "return_value.__no_real_delete = true;" << endl | |
2634 << INDENT << "return return_value;" << endl; | |
2635 } | |
111 | 2636 } |
2637 s << "}" << endl << endl; | |
110 | 2638 } |
2639 | |
2640 | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2641 void DGenerator::writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class) |
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2642 { |
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2643 s << "extern(C) void* qtd_" << d_class->name() << "_d_pointer(void *obj);" << endl |
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2644 << "extern(C) void qtd_" << d_class->name() << "_create_link(void *obj, void* d_obj);" << endl << endl; |
110 | 2645 s << "private extern (C) void qtd_D_" << d_class->name() << "_delete(void *d_ptr) {" << endl |
2646 << " auto d_ref = cast(QObject) d_ptr;" << endl | |
2647 << " d_ref.__no_real_delete = true;" << endl | |
2648 << " delete d_ref;" << endl | |
2649 << "}" << endl << endl; | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2650 } |
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2651 |
1 | 2652 /* |
2653 void DGenerator::writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class) | |
2654 { | |
2655 | |
2656 } | |
2657 */ | |
2658 void DGenerator::marshallFromCppToD(QTextStream &s, const ComplexTypeEntry* ctype) | |
2659 { | |
2660 if(ctype->isQObject()) { | |
2661 QString type_name = ctype->name(); | |
2662 | |
2663 if(ctype->isAbstract()) | |
2664 type_name = type_name + "_ConcreteWrapper"; | |
2665 | |
2666 s << INDENT << "if (__qt_return_value is null)" << endl | |
2667 << INDENT << " return null;" << endl | |
2668 << INDENT << "void* d_obj = __QObject_entity(__qt_return_value);" << endl | |
2669 << INDENT << "if (d_obj is null) {" << endl | |
2670 << INDENT << " auto new_obj = new " << type_name << "(__qt_return_value, true);" << endl | |
2671 << INDENT << " new_obj.__no_real_delete = true;" << endl | |
2672 << INDENT << " return new_obj;" << endl | |
2673 << INDENT << "} else" << endl | |
2674 << INDENT << " return cast(" << ctype->name() << ") d_obj;" << endl; | |
2675 } else if (ctype->isValue() && !ctype->isStructInD()) | |
2676 s << INDENT << "return new " << ctype->name() << "(__qt_return_value, false);" << endl; | |
2677 else if (ctype->isVariant()) | |
2678 s << INDENT << "return new QVariant(__qt_return_value, false);" << endl; | |
2679 else if (ctype->name() == "QModelIndex" || ctype->isStructInD()) | |
2680 s << INDENT << "return __qt_return_value;" << endl; | |
2681 else if (ctype->isObject()) { | |
2682 QString type_name = ctype->name(); | |
2683 | |
2684 if(ctype->isAbstract()) | |
2685 type_name = type_name + "_ConcreteWrapper"; | |
2686 | |
2687 QString return_type_name = ctype->name(); | |
2688 if(ctype->designatedInterface()) | |
2689 return_type_name = ctype->designatedInterface()->name(); | |
2690 | |
2691 AbstractMetaClass *d_class = NULL; | |
2692 | |
2693 d_class = ClassFromEntry::get(ctype); | |
2694 | |
2695 // if class has virtual functions then it has classname_entity function so | |
2696 // we can look for D Object pointer. otherwise create new wrapper | |
2697 if (d_class != NULL && d_class->hasVirtualFunctions()) { | |
2698 s << INDENT << "void* d_obj = __" << ctype->name() << "_entity(__qt_return_value);" << endl | |
2699 << INDENT << "if (d_obj !is null) {" << endl | |
2700 << INDENT << " auto d_obj_ref = cast (Object) d_obj;" << endl | |
2701 << INDENT << " return cast(" << return_type_name << ") d_obj_ref;" << endl | |
2702 << INDENT << "} else {" << endl | |
2703 << INDENT << " auto return_value = new " << type_name << "(__qt_return_value, true);" << endl | |
2704 << INDENT << " return_value.__no_real_delete = true;" << endl | |
2705 << INDENT << " return return_value;" << endl | |
2706 << INDENT << "}" << endl; | |
2707 } else { | |
2708 s << INDENT << "auto return_value = new " << type_name << "(__qt_return_value, true);" << endl | |
2709 << INDENT << "return_value.__no_real_delete = true;" << endl | |
2710 << INDENT << "return return_value;" << endl; | |
2711 } | |
2712 } | |
2713 | |
2714 } | |
2715 | |
2716 void DGenerator::writeNativeField(QTextStream &s, const AbstractMetaField *field) | |
2717 { | |
2718 Q_ASSERT(field->isPublic() || field->isProtected()); | |
2719 | |
2720 const AbstractMetaClass *declaringClass = field->enclosingClass(); | |
2721 | |
2722 FieldModification mod = declaringClass->typeEntry()->fieldModification(field->name()); | |
2723 | |
2724 // Set function | |
2725 if (mod.isWritable() && !field->type()->isConstant()) { | |
2726 const AbstractMetaFunction *setter = field->setter(); | |
2727 if (declaringClass->hasFunction(setter)) { | |
2728 QString warning = | |
2729 QString("class '%1' already has setter '%2' for public field '%3'") | |
2730 .arg(declaringClass->name()).arg(setter->name()).arg(field->name()); | |
2731 ReportHandler::warning(warning); | |
2732 } else { | |
2733 if (!notWrappedYet(setter)) | |
2734 writePrivateNativeFunction(s, setter); | |
2735 } | |
2736 } | |
2737 | |
2738 // Get function | |
2739 const AbstractMetaFunction *getter = field->getter(); | |
2740 if (mod.isReadable()) { | |
2741 if (declaringClass->hasFunction(getter)) { | |
2742 QString warning = | |
2743 QString("class '%1' already has getter '%2' for public field '%3'") | |
2744 .arg(declaringClass->name()).arg(getter->name()).arg(field->name()); | |
2745 ReportHandler::warning(warning); | |
2746 } else { | |
2747 if (!notWrappedYet(getter)) | |
2748 writePrivateNativeFunction(s, getter); | |
2749 } | |
2750 } | |
2751 } | |
2752 | |
2753 void DGenerator::writeSignalConnectors(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunctionList signal_funcs) | |
2754 { | |
2755 s << INDENT << "private static SlotConnector[" << signal_funcs.size() << "] __slotConnectors;" << endl; | |
2756 s << INDENT << "private static SlotConnector[" << signal_funcs.size() << "] __slotDisconnectors;" << endl << endl; | |
2757 | |
2758 s << INDENT << "protected void onSignalHandlerCreated(ref SignalHandler sh) {" << endl; | |
2759 { | |
2760 Indentation indent(INDENT); | |
2761 s << INDENT << "sh.firstSlotConnected = &onFirstSlot;" << endl; | |
2762 s << INDENT << "sh.lastSlotDisconnected = &onLastSlot;" << endl << endl; | |
2763 | |
2764 for(int i = 0; i < signal_funcs.size(); i++) { | |
2765 AbstractMetaFunction *signal = signal_funcs.at(i); | |
2766 QString sigExternName = signalExternName(d_class, signal); | |
2767 s << INDENT << "__slotConnectors[" << i << "] = &" << sigExternName << "_connect;" << endl; | |
2768 s << INDENT << "__slotDisconnectors[" << i << "] = &" << sigExternName << "_disconnect;" << endl; | |
2769 } | |
2770 } | |
2771 s << INDENT << "}" << endl << endl; | |
2772 | |
2773 s << INDENT << "private final void onFirstSlot(int signalId) {" << endl; | |
2774 { | |
2775 Indentation indent(INDENT); | |
2776 s << INDENT << "if (signalId < __slotConnectors.length) {" << endl; | |
2777 s << INDENT << " __slotConnectors[signalId](nativeId);" << endl; | |
2778 s << INDENT << "}" << endl; | |
2779 } | |
2780 s << INDENT << "}" << endl; | |
2781 | |
2782 s << INDENT << "private final void onLastSlot(int signalId) {" << endl; | |
2783 { | |
2784 Indentation indent(INDENT); | |
2785 s << INDENT << "if (signalId < __slotDisconnectors.length) {" << endl; | |
2786 s << INDENT << " __slotDisconnectors[signalId](nativeId);" << endl; | |
2787 s << INDENT << "}" << endl; | |
2788 } | |
2789 s << INDENT << "}" << endl; | |
2790 } | |
2791 | |
2792 void DGenerator::writeSignal(QTextStream &s, const AbstractMetaFunction *d_function) | |
2793 { | |
2794 Q_ASSERT(d_function->isSignal()); | |
2795 | |
2796 AbstractMetaArgumentList arguments = d_function->arguments(); | |
2797 int sz = arguments.count(); | |
2798 | |
2799 s << INDENT << "mixin Signal!(\"" << d_function->name() << "\""; | |
2800 | |
2801 if (sz > 0) { | |
2802 for (int i=0; i<sz; ++i) { | |
2803 s << ", "; | |
2804 | |
2805 QString modifiedType = d_function->typeReplaced(i+1); | |
2806 | |
2807 if (modifiedType.isEmpty()) | |
2808 s << translateType(arguments.at(i)->type(), d_function->implementingClass(), BoxedPrimitive); | |
2809 else | |
2810 s << modifiedType; | |
2811 } | |
2812 } | |
2813 | |
2814 s << ");" << endl; | |
2815 } | |
2816 | |
2817 void DGenerator::writeShellVirtualFunction(QTextStream &s, const AbstractMetaFunction *d_function, | |
2818 const AbstractMetaClass *implementor, int id) | |
2819 { | |
2820 Q_UNUSED(id); | |
2821 Q_UNUSED(implementor); | |
2822 | |
2823 s << "private extern(C) "; | |
2824 CppImplGenerator::writeVirtualDispatchFunction(s, d_function, true); | |
2825 s << "{" << endl; | |
2826 | |
2827 const AbstractMetaClass *own_class = d_function->ownerClass(); | |
2828 | |
2829 s << INDENT << "auto d_object = cast(" << own_class->name() << ") d_entity;" << endl; | |
2830 | |
2831 // the function arguments | |
2832 AbstractMetaArgumentList arguments = d_function->arguments(); | |
2833 foreach (const AbstractMetaArgument *argument, arguments) | |
2834 if (!d_function->argumentRemoved(argument->argumentIndex() + 1)) { | |
2835 QString arg_name = argument->indexedName(); | |
2836 AbstractMetaType *type = argument->type(); | |
2837 // if has QString argument we have to pass char* and str.length to QString constructor | |
2838 { | |
2839 if(type->isEnum()) | |
2840 s << INDENT << "auto " << arg_name << "_enum = cast(" | |
2841 << type->typeEntry()->qualifiedTargetLangName() << ") " << arg_name << ";"; | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
2842 else if (type->typeEntry()->qualifiedCppName() == "QChar") |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
2843 s << INDENT << "auto " << arg_name << "_d_ref = cast(wchar" << QString(type->actualIndirections(), '*') |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
2844 << ") " << arg_name << ";"; |
1 | 2845 else if (type->isTargetLangString()) |
2846 s << INDENT << "string " << arg_name << "_d_ref = toString(" | |
2847 << arg_name << "[0.." << arg_name << "_size]);"; | |
2848 else if (type->typeEntry()->isValue() && type->isNativePointer() && type->typeEntry()->name() == "QString") { | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
2849 s << INDENT << "auto " << arg_name << "_d_qstr = QString(" << arg_name << ", true);" << endl |
1 | 2850 << INDENT << "string " << arg_name << "_d_ref = " << arg_name << "_d_qstr.toNativeString();"; |
2851 } else if(type->isVariant()) | |
2852 s << INDENT << "scope " << arg_name << "_d_ref = new QVariant(" << arg_name << ", true);"; | |
2853 else if (type->typeEntry()->isStructInD()) | |
2854 continue; | |
2855 else if (!type->hasNativeId() && !(type->typeEntry()->isValue() && type->isNativePointer())) | |
2856 continue; | |
2857 else if(type->isObject() | |
2858 || (type->typeEntry()->isValue() && type->isNativePointer()) | |
2859 || type->isValue() || type->isVariant()) { | |
2860 QString type_name = type->typeEntry()->name(); | |
2861 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); | |
2862 if(ctype->isAbstract()) | |
2863 type_name = type_name + "_ConcreteWrapper"; | |
2864 s << INDENT << "scope " << arg_name << "_d_ref = new " << type_name << "(" << arg_name << ", true);"; | |
2865 } | |
2866 else if (type->isQObject()) { | |
2867 QString type_name = type->name(); | |
2868 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(type->typeEntry()); | |
2869 if(ctype->isAbstract()) | |
2870 type_name = type_name + "_ConcreteWrapper"; | |
2871 | |
2872 s << INDENT << "scope " << arg_name << "_d_ref = new " << type_name << "(" << arg_name <<", true);" << endl | |
2873 << INDENT << arg_name << "_d_ref.__no_real_delete = true;"; | |
2874 } | |
2875 s << endl; | |
2876 } | |
2877 } | |
2878 | |
2879 s << INDENT; | |
2880 AbstractMetaType *return_type = d_function->type(); | |
2881 QString new_return_type = QString(d_function->typeReplaced(0)).replace('$', '.'); | |
2882 bool has_return_type = new_return_type != "void" | |
2883 && (!new_return_type.isEmpty() || return_type != 0); | |
2884 if(has_return_type) { | |
2885 AbstractMetaType *f_type = d_function->type(); | |
2886 if(f_type && (f_type->isObject() || f_type->isQObject() || f_type->isVariant() || | |
2887 (f_type->isValue() && !f_type->typeEntry()->isStructInD()))) | |
2888 { | |
2889 QString f_type_name = f_type->name(); | |
2890 if(f_type->typeEntry()->designatedInterface()) | |
2891 f_type_name = f_type->typeEntry()->designatedInterface()->name(); | |
2892 s << f_type_name << " ret_value = "; | |
2893 } | |
2894 else if (f_type && f_type->isTargetLangString()) | |
2895 s << "string _d_str = "; | |
81 | 2896 else if (f_type && (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD())) |
1 | 2897 s << "*__d_return_value = "; |
2898 else | |
2899 s << "auto return_value = "; | |
2900 } | |
2901 s << "d_object." << d_function->name() << "("; | |
2902 | |
2903 uint nativeArgCount = 0; | |
2904 foreach (const AbstractMetaArgument *argument, arguments) | |
2905 if (!d_function->argumentRemoved(argument->argumentIndex() + 1)) { | |
2906 QString arg_name = argument->indexedName(); | |
2907 const AbstractMetaType *type = argument->type(); | |
2908 | |
2909 if (nativeArgCount > 0) | |
2910 s << "," << " "; | |
2911 | |
2912 QString modified_type = d_function->typeReplaced(argument->argumentIndex() + 1); | |
2913 if (!modified_type.isEmpty()) | |
2914 modified_type = modified_type.replace('$', '.'); | |
2915 | |
2916 if (modified_type == "string" /* && type->fullName() == "char" */) | |
2917 s << "fromStringz(" << arg_name << ")"; | |
2918 else { | |
2919 if(type->isContainer() | |
2920 || (type->isReference() && type->typeEntry()->isStructInD())) | |
2921 s << "*"; | |
2922 s << arg_name; | |
2923 } | |
2924 if (type->typeEntry()->isStructInD()) ; | |
2925 else if (type->isQObject() || type->isObject() | |
2926 || (type->typeEntry()->isValue() && type->isNativePointer()) | |
2927 || type->isValue() | |
2928 || type->isTargetLangString() || type->isVariant()) | |
2929 s << "_d_ref"; | |
2930 else if(type->isEnum()) | |
2931 s << "_enum"; | |
2932 | |
2933 nativeArgCount++; | |
2934 } | |
2935 s << ");" << endl; | |
2936 | |
2937 // check for arguments that may return value | |
2938 foreach (const AbstractMetaArgument *argument, arguments) | |
2939 if (!d_function->argumentRemoved(argument->argumentIndex() + 1)) { | |
2940 QString arg_name = argument->indexedName(); | |
2941 AbstractMetaType *type = argument->type(); | |
2942 | |
2943 if (type->typeEntry()->isValue() && type->isNativePointer() && type->typeEntry()->name() == "QString") | |
2944 s << INDENT << arg_name << "_d_qstr.assign(" << arg_name << "_d_ref);" << endl; | |
2945 } | |
2946 | |
2947 if(has_return_type) { | |
2948 AbstractMetaType *f_type = d_function->type(); | |
2949 if(f_type) { | |
2950 if(f_type->isObject() || f_type->isQObject() || f_type->isVariant() || | |
2951 (f_type->isValue() && !f_type->typeEntry()->isStructInD())) { | |
2952 QString native_id = "nativeId"; | |
2953 if (f_type->typeEntry()->designatedInterface()) | |
2954 native_id = "__ptr_" + f_type->typeEntry()->designatedInterface()->name(); | |
2955 s << INDENT << "return ret_value is null? null : ret_value." << native_id << ";" << endl; | |
2956 } else if (f_type->isTargetLangString()) | |
104 | 2957 s << INDENT << "*ret_str = _d_str;" << endl; |
1 | 2958 else if (f_type->isContainer()) |
2959 s << INDENT << "*__d_arr_ptr = return_value.ptr;" << endl | |
2960 << INDENT << "*__d_arr_size = return_value.length;" << endl; | |
81 | 2961 else if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) |
1 | 2962 ; |
2963 else | |
2964 s << INDENT << "return return_value;" << endl; | |
2965 } else | |
2966 s << INDENT << "return return_value;" << endl; | |
2967 | |
2968 } | |
2969 | |
2970 s << "}" << endl << endl; | |
2971 } | |
2972 | |
2973 void DGenerator::generate() | |
2974 { | |
2975 // qtd | |
2976 // code for including classses in 1 module for avoiding circular imports | |
2977 foreach (AbstractMetaClass *cls, m_classes) { | |
2978 const ComplexTypeEntry *ctype = cls->typeEntry(); | |
2979 | |
2980 if (!cls->isInterface() && cls->isAbstract()) { | |
2981 ComplexTypeEntry *ctype_m = (ComplexTypeEntry *)ctype; | |
2982 ctype_m->setAbstract(true); | |
2983 } | |
2984 | |
2985 foreach(QString child, ctype->includedClasses) { | |
2986 ComplexTypeEntry *ctype_child = TypeDatabase::instance()->findComplexType(child); | |
2987 ctype_child->addedTo = cls->name(); | |
2988 } | |
2989 | |
2990 foreach (AbstractMetaFunction *function, cls->functions()) | |
2991 function->checkStoreResult(); | |
110 | 2992 |
2993 // generate QObject conversion functions only those that are required | |
2994 AbstractMetaFunctionList d_funcs = cls->functionsInTargetLang(); | |
2995 for (int i=0; i<d_funcs.size(); ++i) { | |
2996 AbstractMetaType *f_type = d_funcs.at(i)->type(); | |
2997 if (!f_type) | |
2998 continue; | |
2999 if (f_type->isQObject() || f_type->isObject()) { | |
3000 const ComplexTypeEntry* cte = static_cast<const ComplexTypeEntry *>(f_type->typeEntry()); | |
3001 AbstractMetaClass* d_class = ClassFromEntry::get(cte); | |
3002 if (d_class) | |
3003 d_class->needsConversionFunc = true; | |
3004 } | |
3005 } | |
1 | 3006 } |
3007 | |
3008 Generator::generate(); | |
3009 | |
3010 { | |
3011 const AbstractMetaClass *last_class = 0; | |
3012 QFile file("mjb_nativepointer_api.log"); | |
3013 if (file.open(QFile::WriteOnly)) { | |
3014 QTextStream s(&file); | |
3015 | |
3016 AbstractMetaFunctionList nativepointer_functions; | |
3017 for (int i=0; i<m_nativepointer_functions.size(); ++i) { | |
3018 AbstractMetaFunction *f = const_cast<AbstractMetaFunction *>(m_nativepointer_functions[i]); | |
3019 if (f->ownerClass() == f->declaringClass() || f->isFinal()) | |
3020 nativepointer_functions.append(f); | |
3021 } | |
3022 | |
3023 s << "Number of public or protected functions with QNativePointer API: " << nativepointer_functions.size() << endl; | |
3024 foreach (const AbstractMetaFunction *f, nativepointer_functions) { | |
3025 if (last_class != f->ownerClass()) { | |
3026 last_class = f->ownerClass(); | |
3027 s << endl << endl<< "Class " << last_class->name() << ":" << endl; | |
3028 s << "---------------------------------------------------------------------------------" | |
3029 << endl; | |
3030 } | |
3031 | |
3032 s << f->minimalSignature() << endl; | |
3033 } | |
3034 | |
3035 m_nativepointer_functions.clear(); } | |
3036 } | |
3037 | |
3038 { | |
3039 const AbstractMetaClass *last_class = 0; | |
3040 QFile file("mjb_object_type_usage.log"); | |
3041 if (file.open(QFile::WriteOnly)) { | |
3042 QTextStream s(&file); | |
3043 | |
3044 AbstractMetaFunctionList resettable_object_functions; | |
3045 for (int i=0; i<m_resettable_object_functions.size(); ++i) { | |
3046 AbstractMetaFunction *f = const_cast<AbstractMetaFunction *>(m_resettable_object_functions[i]); | |
3047 if (f->ownerClass() == f->declaringClass() || f->isFinal()) | |
3048 resettable_object_functions.append(f); | |
3049 } | |
3050 | |
3051 s << "Number of public or protected functions that return a non-QObject object type, or that are virtual and take a non-QObject object type argument: " << resettable_object_functions.size() << endl; | |
3052 foreach (const AbstractMetaFunction *f, resettable_object_functions) { | |
3053 if (last_class != f->ownerClass()) { | |
3054 last_class = f->ownerClass(); | |
3055 s << endl << endl<< "Class " << last_class->name() << ":" << endl; | |
3056 s << "---------------------------------------------------------------------------------" | |
3057 << endl; | |
3058 } | |
3059 | |
3060 s << f->minimalSignature() << endl; | |
3061 } | |
3062 | |
3063 m_resettable_object_functions.clear(); } | |
3064 } | |
3065 | |
3066 { | |
3067 QFile file("mjb_reference_count_candidates.log"); | |
3068 if (file.open(QFile::WriteOnly)) { | |
3069 QTextStream s(&file); | |
3070 | |
3071 s << "The following functions have a signature pattern which may imply that" << endl | |
3072 << "they need to apply reference counting to their arguments (" | |
3073 << m_reference_count_candidate_functions.size() << " functions) : " << endl; | |
3074 | |
3075 foreach (const AbstractMetaFunction *f, m_reference_count_candidate_functions) { | |
3076 s << f->implementingClass()->fullName() << " : " << f->minimalSignature() << endl; | |
3077 } | |
3078 } | |
3079 file.close(); | |
3080 } | |
3081 } | |
3082 | |
3083 void DGenerator::writeFunctionAttributes(QTextStream &s, const AbstractMetaFunction *d_function, | |
3084 uint included_attributes, uint excluded_attributes, | |
3085 uint options) | |
3086 { | |
3087 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes; | |
3088 | |
3089 if ((attr & AbstractMetaAttributes::Public) || (attr & AbstractMetaAttributes::Protected)) { | |
3090 | |
3091 // Does the function use native pointer API? | |
3092 bool nativePointer = d_function->type() && d_function->type()->isNativePointer() | |
3093 && d_function->typeReplaced(0).isEmpty(); | |
3094 | |
3095 // Does the function need to be considered for resetting the Java objects after use? | |
3096 bool resettableObject = false; | |
3097 | |
3098 if (!nativePointer | |
3099 && d_function->type() | |
3100 && d_function->type()->hasInstantiations() | |
3101 && d_function->typeReplaced(0).isEmpty()) { | |
3102 | |
3103 QList<AbstractMetaType *> instantiations = d_function->type()->instantiations(); | |
3104 | |
3105 foreach (const AbstractMetaType *type, instantiations) { | |
3106 if (type && type->isNativePointer()) { | |
3107 nativePointer = true; | |
3108 break; | |
3109 } | |
3110 } | |
3111 | |
3112 } | |
3113 | |
3114 AbstractMetaArgumentList arguments = d_function->arguments(); | |
3115 if (!nativePointer || (!resettableObject && !d_function->isFinal())) { | |
3116 foreach (const AbstractMetaArgument *argument, arguments) { | |
3117 if (!d_function->argumentRemoved(argument->argumentIndex()+1) | |
3118 && d_function->typeReplaced(argument->argumentIndex()+1).isEmpty()) { | |
3119 | |
3120 if (argument->type()->isNativePointer()) { | |
3121 | |
3122 nativePointer = true; | |
3123 if (resettableObject) break ; | |
3124 | |
3125 } else if (!d_function->isFinalInTargetLang() | |
3126 && argument->type()->isObject() | |
3127 && !argument->type()->isQObject() | |
3128 && !d_function->resetObjectAfterUse(argument->argumentIndex()+1) | |
3129 && d_function->ownership(d_function->declaringClass(), TypeSystem::ShellCode, argument->argumentIndex()+1) == TypeSystem::InvalidOwnership) { | |
3130 | |
3131 resettableObject = true; | |
3132 if (nativePointer) break ; | |
3133 | |
3134 } else if (argument->type()->hasInstantiations()) { | |
3135 | |
3136 QList<AbstractMetaType *> instantiations = argument->type()->instantiations(); | |
3137 foreach (AbstractMetaType *type, instantiations) { | |
3138 if (type && type->isNativePointer()) { | |
3139 nativePointer = true; | |
3140 if (resettableObject) break; | |
3141 } else if (!d_function->isFinal() | |
3142 && type | |
3143 && type->isObject() | |
3144 && !type->isQObject() | |
3145 && !d_function->resetObjectAfterUse(argument->argumentIndex()+1)) { | |
3146 resettableObject = true; | |
3147 if (nativePointer) break ; | |
3148 } | |
3149 } | |
3150 | |
3151 if (nativePointer && resettableObject) | |
3152 break; | |
3153 | |
3154 } | |
3155 } | |
3156 } | |
3157 } | |
3158 | |
3159 if (nativePointer && !m_nativepointer_functions.contains(d_function)) | |
3160 m_nativepointer_functions.append(d_function); | |
3161 if (resettableObject && !m_resettable_object_functions.contains(d_function)) | |
3162 m_resettable_object_functions.append(d_function); | |
3163 } | |
3164 | |
3165 if ((options & SkipAttributes) == 0) { | |
3166 if (d_function->isEmptyFunction() | |
3167 || d_function->isDeprecated()) s << INDENT << "deprecated "; | |
3168 /* | |
3169 bool needsSuppressUnusedWarning = TypeDatabase::instance()->includeEclipseWarnings() | |
3170 && d_function->isSignal() | |
3171 && (((excluded_attributes & AbstractMetaAttributes::Private) == 0) | |
3172 && (d_function->isPrivate() | |
3173 || ((included_attributes & AbstractMetaAttributes::Private) != 0))); | |
3174 | |
3175 if (needsSuppressUnusedWarning && d_function->needsSuppressUncheckedWarning()) { | |
3176 s << INDENT<< "@SuppressWarnings({\"unchecked\", \"unused\"})" << endl; | |
3177 } else if (d_function->needsSuppressUncheckedWarning()) { | |
3178 s << INDENT<< "@SuppressWarnings(\"unchecked\")" << endl; | |
3179 } else if (needsSuppressUnusedWarning) { | |
3180 s << INDENT<< "@SuppressWarnings(\"unused\")" << endl; | |
3181 } | |
3182 | |
3183 if (!(attr & NoBlockedSlot) | |
3184 && !d_function->isConstructor() | |
3185 && !d_function->isSlot() | |
3186 && !d_function->isSignal() | |
3187 && !d_function->isStatic() | |
3188 && !(included_attributes & AbstractMetaAttributes::Static)) | |
3189 s << INDENT << "@QtBlockedSlot" << endl; | |
3190 */ | |
3191 if (!(options & ExternC)) | |
3192 s << INDENT; | |
3193 | |
3194 if (attr & AbstractMetaAttributes::Public) s << "public "; | |
3195 else if (attr & AbstractMetaAttributes::Protected) s << "protected "; | |
3196 else if (attr & AbstractMetaAttributes::Private) s << "private "; | |
3197 else if (attr & AbstractMetaAttributes::Native) s << "private extern(C) "; | |
3198 bool isStatic = (attr & AbstractMetaAttributes::Static); | |
3199 | |
3200 if (attr & AbstractMetaAttributes::Native) ; | |
3201 else if (!isStatic && (attr & AbstractMetaAttributes::FinalInTargetLang)) s << "final "; | |
3202 else if (!isStatic && (attr & AbstractMetaAttributes::Abstract)) s << "abstract "; | |
3203 | |
3204 if (isStatic && !(options & ExternC)) s << "static "; | |
3205 } | |
3206 | |
3207 if ((options & SkipReturnType) == 0) { | |
3208 QString modified_type = d_function->typeReplaced(0); | |
3209 if (options & ExternC) { | |
3210 uint options = 0x0004; // qtd externC | |
3211 s << CppImplGenerator::jniReturnName(d_function, options, true) << " "; | |
3212 } | |
3213 else if (modified_type.isEmpty()) | |
3214 s << translateType(d_function->type(), d_function->implementingClass(), (Option) options); | |
3215 else | |
3216 s << modified_type.replace('$', '.'); | |
3217 s << " "; | |
3218 } | |
3219 | |
3220 } | |
3221 | |
3222 void DGenerator::writeConstructorContents(QTextStream &s, const AbstractMetaFunction *d_function) | |
3223 { | |
3224 // Write constructor | |
3225 s << " {" << endl; | |
3226 { | |
3227 Indentation indent(INDENT); | |
3228 bool shellClass = d_function->ownerClass()->generateShellClass(); | |
3229 if (cpp_shared) { | |
3230 if (shellClass && !d_function->ownerClass()->isInterface()) | |
3231 s << INDENT << "if (!init_flag_" << d_function->ownerClass()->name() << ")" << endl | |
3232 << INDENT << " static_init_" << d_function->ownerClass()->name() << "();" << endl << endl; | |
3233 } | |
3234 writeJavaCallThroughContents(s, d_function); | |
3235 | |
3236 // Write out expense checks if present... | |
3237 const AbstractMetaClass *d_class = d_function->implementingClass(); | |
3238 const ComplexTypeEntry *te = d_class->typeEntry(); | |
3239 if (te->expensePolicy().isValid()) { | |
3240 s << endl; | |
3241 const ExpensePolicy &ep = te->expensePolicy(); | |
3242 s << INDENT << "qt.GeneratorUtilities.countExpense(" << d_class->fullName() | |
3243 << ".class, " << ep.cost << ", " << ep.limit << ");" << endl; | |
3244 } | |
3245 | |
3246 foreach (CodeSnip snip, te->codeSnips()) { | |
3247 if (snip.language == TypeSystem::Constructors) { | |
3248 snip.formattedCode(s, INDENT); | |
3249 } | |
3250 } | |
3251 | |
3252 if(d_function->implementingClass()->isQObject()) | |
3253 { | |
3254 bool hasParentArg = false; | |
3255 AbstractMetaArgumentList arguments = d_function->arguments(); | |
37 | 3256 int arg_index = 0; |
1 | 3257 for (int i=0; i<arguments.count(); ++i) { |
3258 const AbstractMetaArgument *arg = arguments.at(i); | |
37 | 3259 if (arg->argumentName().contains("parent", Qt::CaseInsensitive)) { |
3260 arg_index = i; | |
1 | 3261 hasParentArg = true; |
37 | 3262 } |
1 | 3263 } |
3264 | |
37 | 3265 const AbstractMetaArgument *arg = arguments.at(arg_index); |
1 | 3266 // QString ctor_call = d_function->implementingClass()->name() == "QObject"? "this" : "super"; |
3267 QString ctor_call = "this"; | |
3268 if (hasParentArg) { | |
37 | 3269 s << INDENT << "bool gc_managed = " << arg->argumentName() << " is null ? true : false;" << endl |
1 | 3270 << INDENT << ctor_call << "(__qt_return_value, gc_managed);" << endl; |
3271 } else { | |
3272 s << INDENT << ctor_call << "(__qt_return_value, true);" << endl; | |
3273 } | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
3274 |
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
3275 // creating a link object associated with the current QObject for signal handling and metadata |
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
3276 s << INDENT << "qtd_" << d_function->ownerClass()->name() << "_create_link(this.nativeId, cast(void*) this);" << endl; |
1 | 3277 } |
3278 else | |
35 | 3279 s << INDENT << "this(__qt_return_value);" << endl; |
1 | 3280 } |
3281 s << INDENT << "}" << endl << endl; | |
3282 | |
3283 /* qtd // Write native constructor | |
3284 if (d_function->jumpTableId() == -1) | |
3285 writePrivateNativeFunction(s, d_function); | |
3286 */ | |
3287 } | |
3288 | |
3289 void DGenerator::writeFunctionArguments(QTextStream &s, const AbstractMetaFunction *d_function, | |
3290 int argument_count, uint options) | |
3291 { | |
3292 AbstractMetaArgumentList arguments = d_function->arguments(); | |
3293 | |
3294 if (argument_count == -1) | |
3295 argument_count = arguments.size(); | |
3296 | |
3297 for (int i=0; i<argument_count; ++i) { | |
3298 if (!d_function->argumentRemoved(i+1)) { | |
3299 if (i != 0) | |
3300 s << ", "; | |
3301 writeArgument(s, d_function, arguments.at(i), options); | |
3302 } | |
3303 } | |
3304 } | |
3305 | |
3306 | |
3307 void DGenerator::writeExtraFunctions(QTextStream &s, const AbstractMetaClass *d_class) | |
3308 { | |
3309 const ComplexTypeEntry *class_type = d_class->typeEntry(); | |
3310 Q_ASSERT(class_type); | |
3311 | |
3312 CodeSnipList code_snips = class_type->codeSnips(); | |
3313 foreach (const CodeSnip &snip, code_snips) { | |
3314 if ((!d_class->isInterface() && snip.language == TypeSystem::TargetLangCode) | |
3315 || (d_class->isInterface() && snip.language == TypeSystem::Interface)) { | |
3316 s << endl; | |
3317 snip.formattedCode(s, INDENT); | |
3318 } | |
3319 } | |
3320 } | |
3321 | |
3322 | |
3323 void DGenerator::writeToStringFunction(QTextStream &s, const AbstractMetaClass *d_class) | |
3324 { | |
3325 bool generate = d_class->hasToStringCapability() && !d_class->hasDefaultToStringFunction(); | |
3326 bool core = d_class->package() == QLatin1String("qt.core"); | |
3327 bool qevent = false; | |
3328 | |
3329 const AbstractMetaClass *cls = d_class; | |
3330 while (cls) { | |
3331 if (cls->name() == "QEvent") { | |
3332 qevent = true; | |
3333 break; | |
3334 } | |
3335 cls = cls->baseClass(); | |
3336 } | |
3337 | |
3338 if (generate || qevent) { | |
3339 | |
3340 if (qevent && core) { | |
3341 s << endl | |
3342 << " @Override" << endl | |
3343 << " public String toString() {" << endl | |
3344 << " return getClass().getSimpleName() + \"(type=\" + type().name() + \")\";" << endl | |
3345 << " }" << endl; | |
3346 } else { | |
3347 s << endl | |
3348 << " @Override" << endl | |
3349 << " public String toString() {" << endl | |
3350 << " if (nativeId() == 0)" << endl | |
3351 << " throw new QNoNativeResourcesException(\"Function call on incomplete object of type: \" +getClass().getName());" << endl | |
3352 << " return __qt_toString(nativeId());" << endl | |
3353 << " }" << endl | |
3354 << " native String __qt_toString(long __this_nativeId);" << endl; | |
3355 } | |
3356 } | |
3357 } | |
3358 | |
3359 void DGenerator::writeCloneFunction(QTextStream &s, const AbstractMetaClass *d_class) | |
3360 { | |
3361 s << endl | |
3362 << " @Override" << endl | |
3363 << " public " << d_class->name() << " clone() {" << endl | |
3364 << " if (nativeId() == 0)" << endl | |
3365 << " throw new QNoNativeResourcesException(\"Function call on incomplete object of type: \" +getClass().getName());" << endl | |
3366 << " return __qt_clone(nativeId());" << endl | |
3367 << " }" << endl | |
3368 << " native " << d_class->name() << " __qt_clone(long __this_nativeId);" << endl; | |
3369 } | |
3370 | |
3371 ClassFromEntry* ClassFromEntry::m_instance = NULL; | |
3372 | |
3373 ClassFromEntry::ClassFromEntry() | |
3374 { | |
110 | 3375 } |
3376 | |
3377 AbstractMetaClass* ClassFromEntry::get(const TypeEntry *ctype) | |
3378 { | |
3379 if(!m_instance) | |
3380 return NULL; | |
3381 | |
3382 return m_instance->classFromEntry[ctype]; | |
3383 } | |
3384 | |
3385 void ClassFromEntry::construct(const AbstractMetaClassList &classes) | |
3386 { | |
3387 if(!m_instance) { | |
3388 m_instance = new ClassFromEntry; | |
3389 m_instance->setClasses(classes); | |
3390 m_instance->buildHash(); | |
3391 } | |
3392 } | |
3393 | |
3394 void ClassFromEntry::buildHash() | |
3395 { | |
1 | 3396 foreach (AbstractMetaClass *cls, m_classes) { |
3397 const ComplexTypeEntry *ctype = cls->typeEntry(); | |
3398 classFromEntry[ctype] = cls; | |
3399 } | |
3400 } | |
3401 | |
110 | 3402 void ClassFromEntry::print(QTextStream &s) |
1 | 3403 { |
110 | 3404 s << "_fuck_" << m_instance->m_classes.size(); |
3405 foreach (AbstractMetaClass *cls, m_instance->m_classes) { | |
3406 s << cls->name() << endl; | |
3407 } | |
1 | 3408 } |
110 | 3409 |