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