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