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