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