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