Mercurial > projects > qtd
annotate generator/dgenerator.cpp @ 315:2049c3abd348 lifetime
more cleanup
author | maxter <spambox@d-coding.com> |
---|---|
date | Wed, 23 Dec 2009 23:54:39 +0200 |
parents | 80b52f5e97b6 |
children |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** | |
5 ** This file is part of Qt Jambi. | |
6 ** | |
7 ** * Commercial Usage | |
8 * Licensees holding valid Qt Commercial licenses may use this file in | |
9 * accordance with the Qt Commercial License Agreement provided with the | |
10 * Software or, alternatively, in accordance with the terms contained in | |
11 * a written agreement between you and Nokia. | |
12 * | |
13 * | |
14 * GNU General Public License Usage | |
15 * Alternatively, this file may be used under the terms of the GNU | |
16 * General Public License versions 2.0 or 3.0 as published by the Free | |
17 * Software Foundation and appearing in the file LICENSE.GPL included in | |
18 * the packaging of this file. Please review the following information | |
19 * to ensure GNU General Public Licensing requirements will be met: | |
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
22 * exception, Nokia gives you certain additional rights. These rights | |
23 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
24 * the file GPL_EXCEPTION.txt in this package. | |
25 * | |
310 | 26 * Qt for Win1782dows(R) Licensees |
1 | 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() |
310 | 775 /*|| d_function->implementingClass()->typeEntry()->isObject()*/ ) ) { // qtd |
1 | 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 | |
310 | 1683 if (d_class->polymorphicBase() == d_class) |
1684 { | |
1685 s << " override void __deleteNative() {" << endl | |
1686 << " qtd_" << d_class->polymorphicBase()->name() << "_delete(__nativeId);" << endl | |
1687 << " }" << endl; | |
1688 } | |
1 | 1689 } |
1690 | |
257 | 1691 void DGenerator::writeOwnershipSetter(QTextStream &s, const AbstractMetaClass *d_class) |
1 | 1692 { |
1693 if (d_class->isInterface() || d_class->isNamespace()) | |
310 | 1694 { |
1695 //s << INDENT << "void __nativeOwnership(bool value);"; | |
1696 } | |
257 | 1697 else if (d_class->typeEntry()->isObject()) |
1698 {// COMPILER BUG: | |
310 | 1699 //s << INDENT << "void __nativeOwnership(bool value) { super.__nativeOwnership = value; }"; |
257 | 1700 } |
1 | 1701 } |
1702 | |
260 | 1703 |
1 | 1704 void DGenerator::writeSignalHandlers(QTextStream &s, const AbstractMetaClass *d_class) |
1705 { | |
1706 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class); | |
1707 | |
1708 QString attr; | |
1709 | |
1710 s << "// signal handlers" << endl; | |
1711 foreach(AbstractMetaFunction *signal, signal_funcs) { | |
1712 QString sigExternName = signalExternName(d_class, signal); | |
1713 | |
1714 s << "private " << attr << "extern(C) void " << sigExternName << "_connect(void* native_id);" << endl; | |
1715 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
|
1716 /* |
1 | 1717 QString extra_args; |
1718 | |
1719 foreach (AbstractMetaArgument *argument, arguments) { | |
1720 if(argument->type()->isContainer()) { | |
1721 QString arg_name = argument->indexedName(); | |
1722 const AbstractMetaType *arg_type = argument->type(); | |
1723 QString type_string = translateType(argument->type(), signal->implementingClass(), BoxedPrimitive); | |
1724 extra_args += ", " + type_string + " " + arg_name; | |
1725 } | |
1726 } | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
152
diff
changeset
|
1727 */ |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
152
diff
changeset
|
1728 AbstractMetaArgumentList arguments = signal->arguments(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
152
diff
changeset
|
1729 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
152
diff
changeset
|
1730 s << "private extern(C) void " << sigExternName << "_handle(void* d_entity, void** args) {" << endl; |
1 | 1731 { |
1732 Indentation indent(INDENT); | |
1733 s << INDENT << "auto d_object = cast(" << d_class->name() << ") d_entity;" << endl; | |
1734 int sz = arguments.count(); | |
262 | 1735 |
260 | 1736 //TODO: This mostly duplicates virtual function argument generation. Should be merged |
1 | 1737 for (int j=0; j<sz; ++j) { |
1738 AbstractMetaArgument *argument = arguments.at(j); | |
1739 QString arg_name = argument->indexedName(); | |
1740 AbstractMetaType *type = argument->type(); | |
1741 // if has QString argument we have to pass char* and str.length to QString constructor | |
1742 | |
1743 QString arg_ptr = QString("args[%1]").arg(argument->argumentIndex() + 1); | |
1744 | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
152
diff
changeset
|
1745 if (type->isContainer()) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
152
diff
changeset
|
1746 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
|
1747 << 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
|
1748 } else if (type->isTargetLangString()) { |
1 | 1749 s << INDENT << "auto " << arg_name << "_ptr = " << arg_ptr << ";" << endl |
1750 << 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
|
1751 } else if(type->isPrimitive() || type->isEnum() || type->isFlags() || type->typeEntry()->isStructInD()) { |
1 | 1752 QString type_name = argument->type()->typeEntry()->qualifiedTargetLangName(); |
1753 if (type->isFlags()) | |
1754 type_name = "int"; | |
1755 s << INDENT << "auto " << arg_name << " = *(cast(" << type_name << "*)" << arg_ptr << ");"; | |
260 | 1756 } else if (type->isValue() || (type->typeEntry()->isValue() && type->isNativePointer())) { |
1757 s << INDENT << "scope " << arg_name << " = new " << argument->type()->typeEntry()->name() | |
257 | 1758 << "(cast(void*)(" << arg_ptr << "), QtdObjectFlags.skipNativeDelete);" << endl; |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
152
diff
changeset
|
1759 } |
262 | 1760 else if (type->typeEntry()->isObject()) |
1761 { | |
260 | 1762 bool resetAfterUse = !type->isQObject() && signal->resetObjectAfterUse(argument->argumentIndex() + 1); |
262 | 1763 |
310 | 1764 if (resetAfterUse) |
1765 s << "auto " << arg_name << " = scopeObject!(" << type->typeEntry()->name() << ")(" << arg_name << ");"; | |
260 | 1766 else |
1767 { | |
310 | 1768 s << INDENT << "auto " << arg_name << " = " << type->typeEntry()->name() << ".__wrap(" << arg_name |
1769 << ");" << endl; | |
260 | 1770 } |
1771 } | |
262 | 1772 |
1 | 1773 s << endl; |
1774 } | |
1775 // s << INDENT << "Stdout(\"" << d_class->name() << "\", \"" << signal->name() << "\").newline;" << endl; | |
1776 s << INDENT << "d_object." << signal->name() << ".emit("; | |
1777 for (int j = 0; j<sz; ++j) { | |
1778 AbstractMetaArgument *argument = arguments.at(j); | |
1779 QString arg_name = argument->indexedName(); | |
1780 if (j != 0) | |
1781 s << ", "; | |
1782 s << arg_name; | |
1783 } | |
1784 | |
1785 s << ");" << endl; | |
1786 } | |
1787 s << "}" << endl; | |
1788 } | |
1789 } | |
1790 | |
1791 void DGenerator::write(QTextStream &s, const AbstractMetaClass *d_class) | |
1792 { | |
262 | 1793 ReportHandler::debugSparse("Generating class: " + d_class->fullName()); |
1 | 1794 |
1795 bool fakeClass = d_class->attributes() & AbstractMetaAttributes::Fake; | |
1796 | |
253 | 1797 |
1798 QString auxModName = d_class->package() + "." + d_class->name() + "_aux"; | |
1799 FileOut auxFile(outputDirectory() + "/" + subDirectoryForClass(d_class) + "/" + d_class->name() + "_aux.d"); | |
1800 auxFile.isDone = true; | |
1801 auxFile.stream << "module " << auxModName << ";" << endl << endl; | |
1802 | |
310 | 1803 bool staticInit = d_class->isPolymorphic() || (cpp_shared && d_class->generateShellClass() && !d_class->isInterface()); |
253 | 1804 if (staticInit) |
1805 { | |
1806 auxFile.isDone = false; | |
1807 auxFile.stream << "extern(C) void static_init_" << d_class->name() << "();" << endl; | |
1808 auxFile.stream << "static this() { static_init_" << d_class->name() << "; }" << endl << endl; | |
1809 } | |
1810 | |
1 | 1811 if (m_docs_enabled) { |
1812 m_doc_parser = new DocParser(m_doc_directory + "/" + d_class->name().toLower() + ".jdoc"); | |
1813 } | |
1814 if (!m_isRecursive) | |
1815 s << "module " << d_class->package() << "." << d_class->name() <<";" << endl << endl; | |
1816 | |
39 | 1817 /* |
1 | 1818 s << "// some type info" << endl; |
1819 QString hasVirtuals = d_class->hasVirtualFunctions() ? "has" : "doesn't have"; | |
1820 QString isFinal = d_class->isFinal() ? "is" : "is not"; | |
1821 QString isNativeId = d_class->typeEntry()->isNativeIdBased() ? "is" : "is not"; | |
1822 s << "// " << hasVirtuals << " virtual functions" << endl | |
1823 << "// " << isFinal << " final" << endl | |
1824 << "// " << isNativeId << " native id based" << endl << endl | |
1825 << "// " << d_class->generateShellClass() << " shell class" << endl | |
1826 << "// " << d_class->hasVirtualFunctions() << endl | |
1827 << "// " << d_class->hasProtectedFunctions() << endl | |
1828 << "// " << d_class->hasFieldAccessors() << endl | |
1829 << "// " << d_class->typeEntry()->isObject() << endl; | |
39 | 1830 */ |
1 | 1831 |
1832 const ComplexTypeEntry *ctype = d_class->typeEntry(); | |
1833 if (!ctype->addedTo.isEmpty() && !m_isRecursive) { | |
1834 ComplexTypeEntry *ctype_parent = TypeDatabase::instance()->findComplexType(ctype->addedTo); | |
1835 s << "public import " << ctype_parent->javaPackage() << "." << ctype_parent->name() << ";" << endl; | |
1836 return; | |
1837 } | |
1838 | |
1839 if(d_class->isInterface() && !m_isRecursive) { | |
1840 s << "public import " << ctype->javaPackage() << "." << ctype->qualifiedCppName() << ";" << endl; | |
1841 return; | |
1842 } | |
1843 AbstractMetaClassList includedClassesList; | |
1844 | |
1845 /* m_recursive is increasing by 1 each time we fill the import for a class | |
1846 if it equals to 0 or 1 imports Set is cleared before a filling cycle - if there | |
1847 is only one class as usual or if there are many classes in module, but before | |
1848 filling for first class we need to clear Set. Wow :) | |
1849 */ | |
1850 if(ctype->includedClasses.size() > 0) | |
1851 m_recursive = 1; | |
1852 else | |
1853 m_recursive = 0; | |
1854 | |
1855 foreach(QString child, ctype->includedClasses) { | |
1856 ComplexTypeEntry *ctype_child = TypeDatabase::instance()->findComplexType(child); | |
1857 foreach (AbstractMetaClass *cls, m_classes) { | |
1858 if ( cls->name() == ctype_child->name() ) { | |
1859 includedClassesList << cls; | |
1860 fillRequiredImports(cls); | |
1861 excludedTypes2 << cls->name(); | |
1862 } | |
1863 } | |
1864 } | |
1865 | |
1866 QString interface; | |
1867 if(d_class->typeEntry()->designatedInterface()) | |
1868 interface = d_class->typeEntry()->designatedInterface()->name(); | |
1869 | |
1870 if(d_class->typeEntry()->designatedInterface()) { | |
1871 foreach (AbstractMetaClass *cls, m_classes) { | |
1872 if ( cls->name() == interface ) { | |
1873 includedClassesList << cls; | |
1874 fillRequiredImports(cls); | |
1875 excludedTypes2 << cls->name(); | |
1876 } | |
1877 } | |
1878 } | |
1879 | |
1880 fillRequiredImports(d_class); | |
1881 excludedTypes2 << d_class->name(); | |
1882 if(ctype->includedClasses.size() > 0) | |
1883 m_recursive = 0; | |
1884 | |
1885 QList<Include> includes = d_class->typeEntry()->extraIncludes(); | |
1886 foreach (const Include &inc, includes) { | |
1887 if (inc.type == Include::TargetLangImport) { | |
1888 s << inc.toString() << endl; | |
1889 } | |
1890 } | |
1891 | |
253 | 1892 // Enums aliases outside of the class - hack |
1893 if (!d_class->enums().isEmpty()) { | |
1894 auxFile.isDone = false; | |
1895 foreach (AbstractMetaEnum *d_enum, d_class->enums()) | |
1896 writeEnum(auxFile.stream, d_enum); | |
1897 } | |
1898 | |
1899 // Auxiliary file contents should have been written at this point | |
1900 if (!auxFile.isDone) | |
1901 { | |
1902 s << "public import " << auxModName << ";" << endl; | |
1903 auxFile.done(); | |
1904 } | |
1905 | |
1 | 1906 if (!m_isRecursive) { |
1907 s << "public import qt.QGlobal;" << endl | |
314
80b52f5e97b6
Structure without common root dir
maxter <spambox@d-coding.com>
parents:
310
diff
changeset
|
1908 << "public import qt.core.Qt;" << endl |
80b52f5e97b6
Structure without common root dir
maxter <spambox@d-coding.com>
parents:
310
diff
changeset
|
1909 << "public import qtd.QtdObject;" << endl |
80b52f5e97b6
Structure without common root dir
maxter <spambox@d-coding.com>
parents:
310
diff
changeset
|
1910 << "import qt.core.QString;" << endl |
80b52f5e97b6
Structure without common root dir
maxter <spambox@d-coding.com>
parents:
310
diff
changeset
|
1911 << "import qtd.Array;" << endl; |
1 | 1912 if (d_class->isQObject()) { |
260 | 1913 s << "public import qt.core.QMetaObject;" << endl; |
314
80b52f5e97b6
Structure without common root dir
maxter <spambox@d-coding.com>
parents:
310
diff
changeset
|
1914 s << "public import qtd.Signal;" << endl; |
1 | 1915 if (d_class->name() != "QObject") |
1916 s << "public import qt.core.QObject;" << endl; | |
262 | 1917 } |
1 | 1918 |
1919 // qtd2 hack! | |
1920 if (d_class->name() == "QCoreApplication") | |
1921 s << "private import qt.core.ArrayOps;" << endl; | |
1922 else if (d_class->name() == "QApplication") | |
1923 s << "private import qt.gui.ArrayOps;" << endl; | |
1924 | |
187
34fe79a9915b
fix forward references caused by unneeded import of ArrayOps2
eldar
parents:
185
diff
changeset
|
1925 /* |
34fe79a9915b
fix forward references caused by unneeded import of ArrayOps2
eldar
parents:
185
diff
changeset
|
1926 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
|
1927 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
|
1928 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
|
1929 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
|
1930 */ |
34fe79a9915b
fix forward references caused by unneeded import of ArrayOps2
eldar
parents:
185
diff
changeset
|
1931 if(d_class->isQObject()) |
34fe79a9915b
fix forward references caused by unneeded import of ArrayOps2
eldar
parents:
185
diff
changeset
|
1932 s << "private import " << d_class->package() << ".ArrayOps2;" << endl; |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
152
diff
changeset
|
1933 |
1 | 1934 s << "// automatic imports-------------" << endl; |
1935 writeRequiredImports(s, d_class); | |
1936 s << endl; | |
1937 if (dPhobos) | |
1938 { | |
1939 s << "import std.stdio;" << endl | |
1940 << "import std.string;" << endl | |
1941 << "import std.utf;" << endl | |
310 | 1942 << "import core.memory;" << endl |
314
80b52f5e97b6
Structure without common root dir
maxter <spambox@d-coding.com>
parents:
310
diff
changeset
|
1943 << "import qtd.Core;" << endl; |
1 | 1944 } |
1945 else | |
1946 { | |
1947 s << "import tango.io.Stdout;" << endl | |
1948 << "import tango.stdc.stringz;" << endl | |
1949 << "import tango.text.convert.Utf;" << endl | |
253 | 1950 << "import tango.core.Memory;" << endl; |
1 | 1951 } |
253 | 1952 |
1953 s << endl << endl; | |
1 | 1954 } |
1955 | |
1956 if (m_doc_parser) { | |
1957 s << m_doc_parser->documentation(d_class) << endl << endl; | |
1958 } | |
1959 | |
188 | 1960 /* qtd s << "@QtJambiGeneratedClass" << endl; |
1961 | |
1962 if ((d_class->typeEntry()->typeFlags() & ComplexTypeEntry::Deprecated) != 0) { | |
1963 s << "@Deprecated" << endl; | |
1964 } | |
1965 */ | |
1966 | |
1967 | |
1 | 1968 if (d_class->isInterface()) { |
1969 s << "public interface "; | |
1970 } else { | |
1971 if (d_class->isPublic()) | |
1972 s << "public "; | |
1973 // else friendly | |
1974 | |
1975 bool force_abstract = (d_class->typeEntry()->typeFlags() & ComplexTypeEntry::ForceAbstract) != 0; | |
1976 if (d_class->isFinal() && !force_abstract) | |
1977 s << "final "; | |
1978 if ((d_class->isAbstract() && !d_class->isNamespace()) || force_abstract) | |
1979 s << "abstract "; | |
1980 | |
1981 if (!d_class->typeEntry()->targetType().isEmpty()) { | |
1982 s << d_class->typeEntry()->targetType() << " "; | |
1983 } else if (d_class->isNamespace() && d_class->functionsInTargetLang().size() == 0) { | |
1984 s << "interface "; | |
1985 } else if (d_class->isNamespace()) { | |
1986 s << "class "; | |
1987 } else { | |
1988 s << "class "; | |
1989 } | |
1990 | |
1991 } | |
1992 | |
1993 const ComplexTypeEntry *type = d_class->typeEntry(); | |
1994 | |
1995 s << d_class->name(); | |
1996 | |
1997 if (type->isGenericClass()) { | |
1998 s << "<"; | |
1999 QList<TypeEntry *> templateArguments = d_class->templateBaseClass()->templateArguments(); | |
2000 for (int i=0; i<templateArguments.size(); ++i) { | |
2001 TypeEntry *templateArgument = templateArguments.at(i); | |
2002 if (i > 0) | |
2003 s << ", "; | |
2004 s << templateArgument->name(); | |
2005 } | |
2006 s << ">"; | |
2007 } | |
2008 | |
2009 if (!d_class->isNamespace() && !d_class->isInterface()) { | |
257 | 2010 s << " : "; |
262 | 2011 if (d_class->baseClass()) { |
257 | 2012 s << d_class->baseClass()->name(); |
262 | 2013 } else { |
310 | 2014 if (d_class->isQObject()) |
257 | 2015 s << "QtdObjectBase"; |
310 | 2016 else |
257 | 2017 s << "QtdObject"; |
1 | 2018 } |
2019 }/* qtd else if (d_class->isInterface()) { | |
2020 s << " extends QtJambiInterface"; | |
2021 }*/ | |
2022 | |
2023 // implementing interfaces... | |
2024 bool implements = false; | |
2025 AbstractMetaClassList interfaces = d_class->interfaces(); | |
2026 if (!interfaces.isEmpty()) { | |
2027 if (!d_class->isInterface()) | |
2028 s << ", "; | |
2029 else { | |
2030 implements = true; | |
262 | 2031 s << " : "; |
1 | 2032 } |
2033 for (int i=0; i<interfaces.size(); ++i) { | |
2034 AbstractMetaClass *iface = interfaces.at(i); | |
2035 if (i) s << ", "; | |
2036 s << iface->name(); | |
2037 } | |
2038 } | |
2039 /* qtd | |
2040 if (isComparable(d_class)) { | |
2041 if (!implements) { | |
2042 implements = true; | |
2043 s << endl << " implements "; | |
2044 } | |
2045 else | |
2046 s << "," << endl << " "; | |
2047 s << "java.lang.Comparable<Object>"; | |
2048 } | |
2049 | |
2050 if (d_class->hasCloneOperator()) { | |
2051 if (!implements) { | |
2052 implements = true; | |
2053 s << endl << " implements "; | |
2054 } | |
2055 else | |
2056 s << "," << endl << " "; | |
2057 s << "java.lang.Cloneable"; | |
2058 } | |
2059 */ | |
2060 s << endl << "{" << endl; | |
2061 | |
2062 Indentation indent(INDENT); | |
2063 | |
2064 // Define variables for reference count mechanism | |
2065 if (!d_class->isInterface() && !d_class->isNamespace()) { | |
2066 QHash<QString, int> variables; | |
2067 foreach (AbstractMetaFunction *function, d_class->functions()) { | |
2068 QList<ReferenceCount> referenceCounts = function->referenceCounts(d_class); | |
2069 foreach (ReferenceCount refCount, referenceCounts) { | |
2070 variables[refCount.variableName] |= refCount.action | |
2071 | refCount.access | |
2072 | (refCount.threadSafe ? ReferenceCount::ThreadSafe : 0) | |
2073 | (function->isStatic() ? ReferenceCount::Static : 0) | |
2074 | (refCount.declareVariable.isEmpty() ? ReferenceCount::DeclareVariable : 0); | |
2075 } | |
2076 } | |
2077 | |
2078 foreach (QString variableName, variables.keys()) { | |
2079 int actions = variables.value(variableName) & ReferenceCount::ActionsMask; | |
262 | 2080 bool threadSafe = variables.value(variableName) & ReferenceCount::ThreadSafe; |
1 | 2081 bool isStatic = variables.value(variableName) & ReferenceCount::Static; |
2082 bool declareVariable = variables.value(variableName) & ReferenceCount::DeclareVariable; | |
2083 int access = variables.value(variableName) & ReferenceCount::AccessMask; | |
2084 | |
2085 if (actions == ReferenceCount::Ignore || !declareVariable) | |
2086 continue; | |
2087 | |
2088 if (((actions & ReferenceCount::Add) == 0) != ((actions & ReferenceCount::Remove) == 0)) { | |
2089 QString warn = QString("either add or remove specified for reference count variable '%1' in '%2' but not both") | |
2090 .arg(variableName).arg(d_class->fullName()); | |
2091 ReportHandler::warning(warn); | |
2092 } | |
2093 s << endl; | |
2094 /* qtd | |
2095 if (TypeDatabase::instance()->includeEclipseWarnings()) | |
2096 s << INDENT << "@SuppressWarnings(\"unused\")" << endl; | |
2097 */ | |
2098 if (actions != ReferenceCount::Set && actions != ReferenceCount::Ignore) { // qtd2 | |
310 | 2099 s << INDENT; |
2100 switch (access) { | |
2101 case ReferenceCount::Private: | |
2102 s << "package "; break; // qtd | |
2103 case ReferenceCount::Protected: | |
2104 s << "protected "; break; | |
2105 case ReferenceCount::Public: | |
2106 s << "public "; break; | |
2107 default: // friendly | |
2108 break; | |
2109 } | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
2110 } // qtd2 |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
2111 |
1 | 2112 if (isStatic) |
2113 s << "static "; | |
2114 | |
2115 if (actions != ReferenceCount::Set && actions != ReferenceCount::Ignore) { | |
2116 s << "Object[] " << variableName << ";" << endl; | |
2117 /* | |
2118 if (threadSafe) | |
2119 s << "java.util.Collections.synchronizedCollection("; | |
2120 s << "new java.util.ArrayList<Object>()"; | |
2121 if (threadSafe) | |
2122 s << ")"; | |
2123 s << ";" << endl;*/ | |
2124 } else if (actions != ReferenceCount::Ignore) { | |
2125 /* qtd2 if (threadSafe) | |
2126 s << "synchronized ";*/ | |
2127 s << "Object " << variableName << " = null;" << endl; | |
2128 } | |
2129 } | |
2130 s << endl; | |
2131 } | |
2132 | |
2133 /* qtd2 | |
2134 if (!d_class->isInterface() && (!d_class->isNamespace() || d_class->functionsInTargetLang().size() > 0) | |
2135 && (d_class->baseClass() == 0 || d_class->package() != d_class->baseClass()->package())) { | |
2136 s << endl | |
2137 << INDENT << "static {" << endl; | |
2138 | |
2139 if (d_class->isNamespace()) { | |
2140 s << INDENT << " qt.QtJambi_LibraryInitializer.init();" << endl; | |
2141 } | |
2142 | |
2143 s << INDENT << " " << d_class->package() << ".QtJambi_LibraryInitializer.init();" << endl | |
2144 << INDENT << "}" << endl; | |
2145 } | |
2146 */ | |
2147 | |
2148 // Enums aliaases | |
2149 foreach (AbstractMetaEnum *d_enum, d_class->enums()) | |
2150 writeEnumAlias(s, d_enum); | |
2151 | |
262 | 2152 // Signals |
253 | 2153 if (d_class->isQObject()) |
1 | 2154 { |
253 | 2155 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class, false); |
2156 writeSignalSignatures(s, d_class, signal_funcs); | |
262 | 2157 |
1 | 2158 foreach (AbstractMetaFunction *signal, signal_funcs) |
253 | 2159 writeSignal(s, signal); |
1 | 2160 } |
2161 | |
2162 // Class has subclasses but also only private constructors | |
2163 if (!d_class->isFinalInTargetLang() && d_class->isFinalInCpp()) { | |
2164 s << endl << INDENT << "/**" << endl | |
2165 << INDENT << " * This constructor is a place holder intended to prevent" << endl | |
2166 << INDENT << " * users from subclassing the class. Certain classes can" << endl | |
2167 << INDENT << " * unfortunately only be subclasses internally. The constructor" << endl | |
2168 << INDENT << " * will indiscriminately throw an exception if called. If the" << endl | |
2169 << INDENT << " * exception is ignored, any use of the constructed object will" << endl | |
2170 << INDENT << " * cause an exception to occur." << endl << endl | |
2171 << INDENT << " * @throws QClassCannotBeSubclassedException" << endl | |
2172 << INDENT << " **/" << endl | |
2173 << INDENT << "protected " << d_class->name() << "() throws QClassCannotBeSubclassedException {" << endl | |
2174 << INDENT << " throw new QClassCannotBeSubclassedException(" << d_class->name() << ".class);" << endl | |
2175 << INDENT << "}" << endl << endl; | |
2176 } | |
2177 s << "// Functions" << endl; | |
2178 | |
2179 // Functions | |
2180 AbstractMetaFunctionList d_funcs = d_class->functionsInTargetLang(); | |
2181 for (int i=0; i<d_funcs.size(); ++i) { | |
2182 AbstractMetaFunction *function = d_funcs.at(i); | |
2183 | |
2184 // If a method in an interface class is modified to be private, this should | |
2185 // not be present in the interface at all, only in the implementation. | |
2186 if (d_class->isInterface()) { | |
2187 uint includedAttributes = 0; | |
2188 uint excludedAttributes = 0; | |
2189 retrieveModifications(function, d_class, &excludedAttributes, &includedAttributes); | |
2190 if (includedAttributes & AbstractMetaAttributes::Private) | |
2191 continue; | |
2192 } | |
2193 | |
2194 if (!notWrappedYet(function)) // qtd2 | |
2195 writeFunction(s, function); | |
2196 // s << function->minimalSignature() << endl; | |
2197 } | |
2198 if(d_class->isInterface()) | |
2199 s << endl << INDENT << "public void* __ptr_" << d_class->name() << "();" << endl << endl; | |
2200 | |
2201 s << "// Field accessors" << endl; | |
2202 // Field accessors | |
2203 AbstractMetaFieldList fields = d_class->fields(); | |
2204 foreach (const AbstractMetaField *field, fields) { | |
2205 if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal())) | |
2206 writeFieldAccessors(s, field); | |
2207 } | |
2208 | |
310 | 2209 writeDestructor(s, d_class); |
253 | 2210 |
1 | 2211 // Add dummy constructor for use when constructing subclasses |
2212 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) { | |
310 | 2213 |
2214 writeObjectFunctions(s, d_class); | |
2215 | |
1 | 2216 s << endl |
2217 << INDENT << "public " | |
2218 << "this"; | |
2219 | |
253 | 2220 |
2221 Indentation indent(INDENT); | |
262 | 2222 |
257 | 2223 QString flags = d_class->hasVirtualFunctions() && d_class->typeEntry()->isObject() ? "QtdObjectFlags.hasDId" : "QtdObjectFlags.none"; |
2224 s << "(void* nativeId, QtdObjectFlags flags = " << flags << ") {" << endl | |
2225 << INDENT << "super(nativeId, flags);" << endl; | |
262 | 2226 |
253 | 2227 /* |
223 | 2228 if (cpp_shared) { |
2229 if (d_class->generateShellClass() && !d_class->isInterface()) | |
253 | 2230 s << INDENT << "if (!static_inited)" << endl |
223 | 2231 << INDENT << " static_init_" << d_class->name() << "();" << endl << endl; |
2232 } | |
253 | 2233 */ |
2234 | |
262 | 2235 |
1 | 2236 // customized store-result instances |
2237 d_funcs = d_class->functionsInTargetLang(); | |
2238 for (int i=0; i<d_funcs.size(); ++i) { | |
2239 AbstractMetaFunction *d_function = d_funcs.at(i); | |
2240 uint included_attributes = 0; | |
2241 uint excluded_attributes = 0; | |
2242 setupForFunction(d_function, &included_attributes, &excluded_attributes); | |
2243 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes; | |
2244 bool isStatic = (attr & AbstractMetaAttributes::Static); | |
2245 | |
2246 if (!isStatic && (attr & AbstractMetaAttributes::Abstract)) | |
2247 continue; | |
2248 | |
2249 if(d_function->storeResult()) { | |
2250 QString type_name = d_function->type()->name(); | |
2251 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry()); | |
2252 if(ctype->isAbstract()) | |
2253 type_name = type_name + "_ConcreteWrapper"; | |
2254 | |
262 | 2255 s << INDENT << " __m_" << d_function->name() << ";" << endl; |
1 | 2256 } |
2257 } | |
2258 | |
2259 // pointers to native interface objects for classes that implement interfaces | |
2260 // initializing | |
2261 interfaces = d_class->interfaces(); | |
2262 if (!interfaces.isEmpty()) { | |
2263 for (int i=0; i<interfaces.size(); ++i) { | |
2264 AbstractMetaClass *iface = interfaces.at(i); | |
2265 | |
2266 s << INDENT << " __m_ptr_" << iface->name() << " = qtd_" << d_class->name() << "_cast_to_" << iface->qualifiedCppName() | |
253 | 2267 << "(__nativeId);" << endl; |
1 | 2268 } |
2269 } | |
2270 | |
2271 | |
2272 s << INDENT << "}" << endl << endl; | |
2273 | |
253 | 2274 /******************!!!DUPLICATE OF ABOVE!!!*********************/ |
1 | 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 | |
2292 s << INDENT << type_name << " __m_" << d_function->name() << ";" << endl; | |
2293 } | |
2294 } | |
2295 /***************************************************************/ | |
2296 | |
2297 // pointers to native interface objects for classes that implement interfaces | |
2298 // initializing | |
2299 interfaces = d_class->interfaces(); | |
2300 if (!interfaces.isEmpty()) { | |
2301 for (int i=0; i<interfaces.size(); ++i) { | |
2302 AbstractMetaClass *iface = interfaces.at(i); | |
2303 | |
2304 s << INDENT << "private void* __m_ptr_" << iface->name() << ";" << endl | |
2305 << INDENT << "public void* __ptr_" << iface->name() << "() { return __m_ptr_" << iface->name() << "; }" << endl << endl; | |
2306 } | |
262 | 2307 } |
1 | 2308 } |
2309 | |
2310 /* qtd | |
2311 // Add a function that converts an array of the value type to a QNativePointer | |
2312 if (d_class->typeEntry()->isValue() && !fakeClass) { | |
2313 s << endl | |
2314 << INDENT << "public static native QNativePointer nativePointerArray(" << d_class->name() | |
2315 << " array[]);" << endl; | |
2316 } | |
2317 | |
2318 // write the cast to this function.... | |
2319 if (d_class->isInterface()) { | |
2320 s << endl | |
2321 << " public long __qt_cast_to_" | |
2322 << static_cast<const InterfaceTypeEntry *>(type)->origin()->targetLangName() | |
2323 << "(long ptr);" << endl; | |
2324 } else { | |
2325 foreach (AbstractMetaClass *cls, interfaces) { | |
2326 s << endl | |
2327 << " @QtBlockedSlot public native long __qt_cast_to_" | |
2328 << static_cast<const InterfaceTypeEntry *>(cls->typeEntry())->origin()->targetLangName() | |
2329 << "(long ptr);" << endl; | |
2330 } | |
2331 } | |
2332 */ | |
2333 | |
2334 /* qtd writeJavaLangObjectOverrideFunctions(s, d_class); | |
2335 */ | |
257 | 2336 writeOwnershipSetter(s, d_class); |
1 | 2337 s << "// Injected code in class" << endl; |
2338 writeExtraFunctions(s, d_class); | |
2339 // qtd2 writeToStringFunction(s, d_class); | |
2340 /* qtd | |
2341 if (d_class->hasCloneOperator()) { | |
2342 writeCloneFunction(s, d_class); | |
2343 } | |
2344 */ | |
2345 s << "}" << endl; | |
2346 | |
262 | 2347 /* ---------------- injected free code ----------------*/ |
2348 const ComplexTypeEntry *class_type = d_class->typeEntry(); | |
2349 Q_ASSERT(class_type); | |
2350 | |
2351 CodeSnipList code_snips = class_type->codeSnips(); | |
2352 foreach (const CodeSnip &snip, code_snips) { | |
2353 if (!d_class->isInterface() && snip.language == TypeSystem::TargetLangFreeCode) { | |
2354 s << endl; | |
2355 snip.formattedCode(s, INDENT); | |
2356 } | |
2357 } | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2358 /* --------------------------------------------------- */ |
14 | 2359 |
1 | 2360 interfaces = d_class->interfaces(); |
2361 if (!interfaces.isEmpty()) { | |
2362 for (int i=0; i<interfaces.size(); ++i) { | |
2363 AbstractMetaClass *iface = interfaces.at(i); | |
2364 | |
2365 s << INDENT << "private static extern (C) void*" << "qtd_" << d_class->name() << "_cast_to_" << iface->qualifiedCppName() | |
2366 << "(void* nativeId);" << endl; | |
2367 } | |
2368 } | |
2369 | |
2370 if (!d_class->isInterface() && d_class->isAbstract()) { | |
2371 s << endl; | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2372 |
1 | 2373 s << INDENT << "public class " << d_class->name() << "_ConcreteWrapper : " << d_class->name() << " {" << endl; |
2374 | |
2375 { | |
262 | 2376 Indentation indent(INDENT); |
257 | 2377 s << INDENT << "public this(void* native_id, QtdObjectFlags flags) {" << endl |
253 | 2378 << INDENT << " super(native_id, flags);" << endl << endl; |
262 | 2379 |
253 | 2380 /******************!!!DUPLICATE!!!*********************/ |
1 | 2381 d_funcs = d_class->functionsInTargetLang(); |
2382 for (int i=0; i<d_funcs.size(); ++i) { | |
2383 AbstractMetaFunction *d_function = d_funcs.at(i); | |
2384 uint included_attributes = 0; | |
2385 uint excluded_attributes = 0; | |
2386 setupForFunction(d_function, &included_attributes, &excluded_attributes); | |
2387 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes; | |
2388 // qtd bool isStatic = (attr & AbstractMetaAttributes::Static); | |
2389 | |
2390 if(d_function->storeResult()) { | |
2391 QString type_name = d_function->type()->name(); | |
2392 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry()); | |
2393 if(ctype->isAbstract()) | |
2394 type_name = type_name + "_ConcreteWrapper"; | |
2395 s << INDENT << " __m_" << d_function->name() << " = new " | |
262 | 2396 << type_name << "(cast(void*)null);" << endl; |
1 | 2397 } |
2398 } | |
2399 | |
2400 s << INDENT << "}" << endl << endl; | |
2401 | |
2402 for (int i=0; i<d_funcs.size(); ++i) { | |
2403 AbstractMetaFunction *d_function = d_funcs.at(i); | |
2404 uint included_attributes = 0; | |
2405 uint excluded_attributes = 0; | |
2406 setupForFunction(d_function, &included_attributes, &excluded_attributes); | |
2407 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes; | |
2408 // qtd bool isStatic = (attr & AbstractMetaAttributes::Static); | |
2409 | |
2410 if(d_function->storeResult()) { | |
2411 QString type_name = d_function->type()->name(); | |
2412 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry()); | |
2413 if(ctype->isAbstract()) | |
2414 type_name = type_name + "_ConcreteWrapper"; | |
2415 | |
2416 s << INDENT << d_function->type()->name() << " __m_" << d_function->name() << ";" << endl; | |
2417 } | |
2418 } | |
2419 /***************************************************************/ | |
2420 | |
2421 | |
2422 | |
2423 | |
2424 | |
2425 | |
2426 uint exclude_attributes = AbstractMetaAttributes::Native | AbstractMetaAttributes::Abstract; | |
2427 uint include_attributes = 0; | |
2428 AbstractMetaFunctionList functions = d_class->queryFunctions(AbstractMetaClass::NormalFunctions | AbstractMetaClass::AbstractFunctions | AbstractMetaClass::NonEmptyFunctions | AbstractMetaClass::NotRemovedFromTargetLang); | |
2429 foreach (const AbstractMetaFunction *d_function, functions) { | |
2430 retrieveModifications(d_function, d_class, &exclude_attributes, &include_attributes); | |
2431 if (notWrappedYet(d_function)) | |
2432 continue; | |
2433 /* qtd s << endl | |
2434 << INDENT << "@Override" << endl; */ | |
2435 writeFunctionAttributes(s, d_function, include_attributes, exclude_attributes, | |
2436 d_function->isNormal() || d_function->isSignal() ? 0 : SkipReturnType); | |
2437 | |
2438 s << d_function->name() << "("; | |
2439 writeFunctionArguments(s, d_function, d_function->arguments().count()); | |
2440 s << ") {" << endl; | |
2441 { | |
2442 Indentation indent(INDENT); | |
2443 writeJavaCallThroughContents(s, d_function, SuperCall); | |
2444 } | |
2445 s << INDENT << "}" << endl; | |
2446 } | |
2447 } | |
2448 s << INDENT << "}" << endl << endl; | |
2449 } | |
2450 | |
310 | 2451 |
2452 if (d_class->isPolymorphic() && d_class->polymorphicBase() == d_class) | |
257 | 2453 { |
310 | 2454 s << "extern(C) void* qtd_" << d_class->name() << "_dId(void *nativeId);" << endl << endl; |
2455 s << "extern(C) void* qtd_" << d_class->name() << "_typeId(void* nativeId);" << endl; | |
1 | 2456 } |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2457 |
310 | 2458 s << "extern(C) void* qtd_" << d_class->name() << "_staticTypeId();" << endl; |
2459 | |
152 | 2460 // if (d_class->needsConversionFunc) |
257 | 2461 // writeConversionFunction(s, d_class); |
2462 | |
310 | 2463 if (d_class->hasConstructors() && d_class->polymorphicBase() == d_class) |
315 | 2464 s << "extern(C) void qtd_" << d_class->name() << "_delete(void *ptr);" << endl << endl; |
1 | 2465 |
2466 // qtd | |
2467 s << endl << "// C wrappers" << endl; | |
2468 d_funcs = d_class->functionsInTargetLang(); | |
2469 if (!d_class->isInterface()) | |
2470 for (int i=0; i<d_funcs.size(); ++i) { | |
2471 AbstractMetaFunction *function = d_funcs.at(i); | |
2472 | |
2473 if (!notWrappedYet(function)) // qtd2 | |
2474 if (function->jumpTableId() == -1) | |
2475 writePrivateNativeFunction(s, function); | |
2476 } | |
2477 | |
2478 | |
2479 s << "// Just the private functions for abstract functions implemeneted in superclasses" << endl; | |
2480 // Just the private functions for abstract functions implemeneted in superclasses | |
2481 if (!d_class->isInterface() && d_class->isAbstract()) { | |
2482 d_funcs = d_class->queryFunctions(AbstractMetaClass::NormalFunctions | AbstractMetaClass::AbstractFunctions | AbstractMetaClass::NotRemovedFromTargetLang); | |
2483 foreach (AbstractMetaFunction *d_function, d_funcs) { | |
2484 if (d_function->implementingClass() != d_class) { | |
2485 s << endl; | |
2486 writePrivateNativeFunction(s, d_function); | |
2487 } | |
2488 } | |
257 | 2489 } |
1 | 2490 |
2491 | |
2492 foreach (const AbstractMetaField *field, fields) { | |
2493 if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal())) | |
2494 writeNativeField(s, field); | |
2495 } | |
2496 s << endl << endl; | |
2497 | |
2498 // qtd | |
2499 s << endl << "// Virtual Dispatch functions" << endl; | |
2500 AbstractMetaFunctionList virtualFunctions = d_class->virtualFunctions(); | |
2501 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { | |
2502 const AbstractMetaFunction *function = virtualFunctions.at(pos); | |
2503 if (!notWrappedYet(function)) // qtd2 | |
2504 writeShellVirtualFunction(s, function, d_class, pos); | |
2505 } | |
2506 | |
253 | 2507 // write static constructor |
2508 if (staticInit) { | |
2509 QString initArgs; | |
2510 if (cpp_shared) | |
2511 { | |
2512 initArgs = "void* virtuals"; | |
1 | 2513 if (d_class->isQObject()) |
253 | 2514 initArgs += ", void* signals"; |
1 | 2515 |
2516 s << "private extern (C) void qtd_" << d_class->name() | |
253 | 2517 << QString("_initCallBacks(%1);").arg(initArgs) << endl << endl; |
2518 } | |
2519 | |
2520 s << "extern(C) void static_init_" << d_class->name() << "() {" << endl; | |
2521 | |
310 | 2522 if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) |
2523 s << " " << d_class->name() << ".__createMetaObject;" << endl << endl; | |
253 | 2524 |
2525 if (cpp_shared) { | |
2526 // virtual functions | |
2527 s << INDENT << "void*[" << virtualFunctions.size() << "] virt_arr;" << endl; | |
1 | 2528 for (int pos = 0; pos<virtualFunctions.size(); ++pos) { |
2529 const AbstractMetaFunction *function = virtualFunctions.at(pos); | |
2530 if (!notWrappedYet(function)) // qtd2 | |
2531 s << INDENT << "virt_arr[" << pos << "] = &" << function->marshalledName() << "_dispatch;" <<endl; | |
2532 } | |
2533 if (virtualFunctions.size() == 0) | |
2534 initArgs = "null"; | |
2535 else | |
2536 initArgs = "virt_arr.ptr"; | |
2537 | |
2538 if (d_class->isQObject()) { | |
253 | 2539 |
2540 // signals | |
1 | 2541 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class); |
2542 s << endl << INDENT << "void*[" << signal_funcs.size() << "] sign_arr;" << endl; | |
2543 for(int i = 0; i < signal_funcs.size(); i++) { | |
2544 AbstractMetaFunction *signal = signal_funcs.at(i); | |
218 | 2545 s << INDENT << "sign_arr[" << i << "] = &" << signalExternName(d_class, signal) << "_handle;" << endl; |
1 | 2546 } |
2547 if(signal_funcs.size() == 0) | |
2548 initArgs += ", null"; | |
2549 else | |
2550 initArgs += ", sign_arr.ptr"; | |
2551 } | |
2552 | |
253 | 2553 s << INDENT << "qtd_" << d_class->name() << QString("_initCallBacks(%1);").arg(initArgs) << endl; |
1 | 2554 } |
253 | 2555 |
2556 s << "}" << endl << endl; | |
1 | 2557 } |
2558 | |
2559 writeSignalHandlers(s, d_class); | |
2560 s << endl; | |
2561 | |
2562 if (m_docs_enabled) { | |
2563 delete m_doc_parser; | |
2564 m_doc_parser = 0; | |
2565 } | |
2566 | |
2567 // qtd multiple classes | |
2568 foreach (AbstractMetaClass *cls, includedClassesList) { | |
2569 m_isRecursive = true; | |
2570 write(s, cls); | |
2571 m_isRecursive = false; | |
2572 } | |
253 | 2573 |
2574 | |
2575 if (d_class->isQObject()) | |
310 | 2576 s << "private extern(C) void qtd_" << d_class->name() << "_createEntity(void* nativeId, void* dId);" << endl << endl; |
1 | 2577 } |
2578 | |
257 | 2579 /* |
110 | 2580 void DGenerator::writeConversionFunction(QTextStream &s, const AbstractMetaClass *d_class) |
2581 { | |
2582 const ComplexTypeEntry *ctype = d_class->typeEntry(); | |
253 | 2583 if(ctype->isQObject() || !ctype->isObject()) |
152 | 2584 return; |
110 | 2585 QString class_name = ctype->name(); |
111 | 2586 QString return_type_name = class_name; |
2587 if(ctype->designatedInterface()) | |
2588 return_type_name = ctype->designatedInterface()->name(); | |
253 | 2589 |
2590 s << return_type_name << " qtd_" << class_name << "_from_ptr(void* ret) {" << endl; | |
2591 | |
2592 | |
2593 QString type_name = class_name; | |
2594 if(ctype->isAbstract()) | |
2595 type_name = ctype->targetLangName() + "_ConcreteWrapper"; | |
2596 | |
2597 // if class has virtual functions then it has classname_entity function so | |
2598 // we can look for D Object pointer. otherwise create new wrapper | |
2599 if (d_class->hasVirtualFunctions()) { | |
257 | 2600 s << INDENT << "void* d_obj = qtd_" << ctype->targetLangName() << "_dId(ret);" << endl |
253 | 2601 << INDENT << "if (d_obj !is null) {" << endl |
2602 << INDENT << " auto d_obj_ref = cast (Object) d_obj;" << endl | |
2603 << INDENT << " return cast(" << return_type_name << ") d_obj_ref;" << endl | |
2604 << INDENT << "} else {" << endl | |
257 | 2605 << INDENT << " auto return_value = new " << type_name << "(ret, QtdObjectFlags.skipNativeDelete);" << endl |
253 | 2606 << INDENT << " return return_value;" << endl |
2607 << INDENT << "}" << endl; | |
2608 } else { | |
257 | 2609 s << INDENT << "auto return_value = new " << type_name << "(ret, QtdObjectFlags.skipNativeDelete);" << endl |
253 | 2610 << INDENT << "return return_value;" << endl; |
111 | 2611 } |
2612 s << "}" << endl << endl; | |
110 | 2613 } |
257 | 2614 */ |
2615 | |
310 | 2616 /* |
257 | 2617 void DGenerator::writeObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class) |
262 | 2618 { |
259 | 2619 // polymorphic |
260 | 2620 if (d_class->isPolymorphic()) |
257 | 2621 { |
259 | 2622 QString rootClassName = d_class->rootClass()->name(); |
2623 QString concreteArg; | |
2624 if (d_class->isAbstract()) | |
262 | 2625 concreteArg += ", " + d_class->name() + "_ConcreteWrapper"; |
259 | 2626 |
2627 s << " private static QtdMetaObject _staticMetaObject;" << endl | |
2628 //<< " private static QtdMetaObject[void*] _nativeToTargetMap;" << endl | |
262 | 2629 |
259 | 2630 << " protected static void createStaticMetaObject() {" << endl |
2631 << " assert(!_staticMetaObject);" << endl | |
2632 << " QtdMetaObject base;" << endl; | |
2633 | |
2634 if (d_class->baseClass()) | |
2635 { | |
2636 QString baseName = d_class->baseClassName(); | |
2637 s << " if (!" << baseName << "._staticMetaObject)" << endl | |
2638 << " " << baseName << ".createStaticMetaObject;" << endl | |
2639 << " base = " << baseName << "._staticMetaObject;" << endl; | |
2640 } | |
262 | 2641 |
259 | 2642 s << " _staticMetaObject = new QtdMetaObject(qtd_" << d_class->name() << "_staticTypeId, base);" << endl |
2643 << " _staticMetaObject.construct!(" << d_class->name() << concreteArg << ");" << endl | |
2644 << " }" << endl << endl | |
2645 | |
2646 << " QtdMetaObject metaObject() {" << endl | |
2647 << " return _staticMetaObject;" << endl | |
2648 << " }" << endl << endl | |
262 | 2649 |
259 | 2650 << " static QtdMetaObject staticMetaObject() {" << endl |
2651 << " return _staticMetaObject;" << endl | |
2652 << " }" << endl << endl | |
2653 | |
262 | 2654 << " static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl |
259 | 2655 << " auto obj = cast(" << d_class->name() << ") qtd_" << rootClassName << "_dId(nativeId);" << endl |
2656 << " if (!obj)" << endl | |
260 | 2657 << " obj = static_cast!(" << d_class->name() << ")(_staticMetaObject.wrap(nativeId, " |
259 | 2658 "qtd_" << rootClassName << "_typeId(nativeId), flags));" << endl |
262 | 2659 << " return obj;" << endl |
2660 << " }" << endl << endl; | |
257 | 2661 } |
259 | 2662 else |
310 | 2663 { |
259 | 2664 } |
257 | 2665 } |
310 | 2666 */ |
2667 | |
2668 void DGenerator::writeObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class) | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2669 { |
253 | 2670 QString concreteArg; |
2671 if (d_class->isAbstract()) | |
2672 concreteArg += ", " + d_class->name() + "_ConcreteWrapper"; | |
2673 | |
310 | 2674 bool isQObject = d_class->isQObject(); |
2675 QString moName = isQObject ? "QMetaObject" : "QtdMetaObject"; | |
2676 | |
2677 s << " private static __gshared " << moName << " _staticMetaObject;" << endl | |
2678 << " static void __createMetaObject(){" << endl | |
2679 << " if (!_staticMetaObject){" << endl | |
2680 << " QtdMetaObjectBase base;" << endl | |
2681 << " static if (is(typeof(super.__createMetaObject))) {" << endl | |
2682 << " alias typeof(super) Base;" << endl | |
2683 << " Base.__createMetaObject();" << endl | |
2684 << " base = Base._staticMetaObject;" << endl | |
2685 << " }" << endl | |
2686 << " _staticMetaObject = new " << moName << "(qtd_" << d_class->name() << "_staticTypeId, base, &__createWrapper);" << endl | |
2687 << " }" << endl | |
2688 << " }" << endl << endl | |
2689 | |
2690 << " " << moName << " metaObject(){" << endl | |
2691 << " return _staticMetaObject;" << endl | |
2692 << " }" << endl << endl | |
2693 << " static " << moName << " staticMetaObject() {" << endl | |
2694 << " return _staticMetaObject;" << endl | |
2695 << " }" << endl << endl | |
2696 | |
2697 << " static QtdObjectBase __createWrapper(void* nativeId, QtdObjectFlags flags) {" << endl; | |
2698 | |
2699 QString className = d_class->name(); | |
2700 if (d_class->isAbstract()) | |
2701 className += "_ConcreteWrapper"; | |
2702 | |
2703 s << " auto obj = new(flags) " << className << "(nativeId, flags);" << endl; | |
2704 | |
2705 if (d_class->isQObject()) | |
2706 s << " qtd_" << d_class->name() << "_createEntity(nativeId, cast(void*)obj);" << endl; | |
2707 | |
2708 s << " return obj;" << endl | |
2709 << " }" << endl << endl; | |
2710 | |
2711 if (!isQObject) | |
2712 { | |
2713 if (d_class->isPolymorphic()) | |
2714 { | |
2715 const AbstractMetaClass* polyBase = d_class->polymorphicBase(); | |
2716 s << " static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl | |
2717 << " auto obj = cast(" << d_class->name() << ") qtd_" << polyBase->name() << "_dId(nativeId);" << endl | |
2718 << " if (!obj)" << endl | |
2719 << " obj = static_cast!(" << d_class->name() << ")(_staticMetaObject.wrap(nativeId, " | |
2720 "qtd_" << polyBase->name() << "_typeId(nativeId), flags));" << endl | |
2721 << " return obj;" << endl | |
2722 << " }" << endl << endl; | |
2723 } | |
2724 else | |
2725 { | |
2726 s << " static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl | |
2727 << " return new(flags) " << d_class->name() << "(nativeId, flags);" << endl | |
2728 << " }" << endl << endl; | |
2729 } | |
253 | 2730 } |
310 | 2731 else |
2732 { | |
2733 s << " static " << d_class->name() << " __wrap(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) {" << endl | |
2734 << " return static_cast!" << d_class->name() << "(" << d_class->name() << "._staticMetaObject.wrap(nativeId, flags));" << endl | |
2735 << " }" << endl << endl; | |
2736 } | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2737 } |
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
104
diff
changeset
|
2738 |
1 | 2739 /* |
2740 void DGenerator::writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class) | |
2741 { | |
2742 | |
2743 } | |
2744 */ | |
257 | 2745 |
259 | 2746 void DGenerator::marshalToD(QTextStream &s, const ComplexTypeEntry *ctype) |
1 | 2747 { |
260 | 2748 if(ctype->isObject()) { |
262 | 2749 s << "return " << ctype->name() << ".__wrap(ret);" << endl; |
259 | 2750 } else if (ctype->isValue() && !ctype->isStructInD()) { |
2751 s << INDENT << "return new " << ctype->name() << "(ret);" << endl; | |
2752 } else if (ctype->isVariant()) { | |
2753 s << INDENT << "return new QVariant(ret);" << endl; | |
152 | 2754 } else if (ctype->name() == "QModelIndex" || ctype->isStructInD()) { |
253 | 2755 s << INDENT << "return ret;" << endl; |
1 | 2756 } |
2757 } | |
2758 | |
2759 void DGenerator::writeNativeField(QTextStream &s, const AbstractMetaField *field) | |
2760 { | |
2761 Q_ASSERT(field->isPublic() || field->isProtected()); | |
2762 | |
2763 const AbstractMetaClass *declaringClass = field->enclosingClass(); | |
2764 | |
2765 FieldModification mod = declaringClass->typeEntry()->fieldModification(field->name()); | |
2766 | |
2767 // Set function | |
2768 if (mod.isWritable() && !field->type()->isConstant()) { | |
2769 const AbstractMetaFunction *setter = field->setter(); | |
2770 if (declaringClass->hasFunction(setter)) { | |
2771 QString warning = | |
2772 QString("class '%1' already has setter '%2' for public field '%3'") | |
2773 .arg(declaringClass->name()).arg(setter->name()).arg(field->name()); | |
2774 ReportHandler::warning(warning); | |
2775 } else { | |
2776 if (!notWrappedYet(setter)) | |
2777 writePrivateNativeFunction(s, setter); | |
2778 } | |
2779 } | |
2780 | |
2781 // Get function | |
2782 const AbstractMetaFunction *getter = field->getter(); | |
2783 if (mod.isReadable()) { | |
2784 if (declaringClass->hasFunction(getter)) { | |
2785 QString warning = | |
2786 QString("class '%1' already has getter '%2' for public field '%3'") | |
2787 .arg(declaringClass->name()).arg(getter->name()).arg(field->name()); | |
2788 ReportHandler::warning(warning); | |
2789 } else { | |
2790 if (!notWrappedYet(getter)) | |
2791 writePrivateNativeFunction(s, getter); | |
2792 } | |
2793 } | |
2794 } | |
2795 | |
253 | 2796 void DGenerator::writeSignalSignatures(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunctionList signal_funcs) |
1 | 2797 { |
253 | 2798 s << INDENT << "private const string[" << signal_funcs.size() << "] __signalSignatures = ["; |
1 | 2799 { |
2800 Indentation indent(INDENT); | |
253 | 2801 for (int i = 0; i < signal_funcs.size(); ++i) |
262 | 2802 { |
253 | 2803 if (i) |
262 | 2804 s << ", "; |
253 | 2805 s << endl << INDENT << " \"" << signal_funcs.at(i)->minimalSignature() << "\""; |
1 | 2806 } |
2807 } | |
253 | 2808 s << INDENT << "];" << endl << endl; |
2809 | |
2810 s << INDENT << "int signalSignature(int signalId, ref stringz signature) {" << endl; | |
1 | 2811 { |
2812 Indentation indent(INDENT); | |
262 | 2813 |
253 | 2814 if (d_class->name() != "QObject") |
2815 { | |
2816 s << INDENT << "signalId = super.signalSignature(signalId, signature);" << endl | |
2817 << INDENT << "if (signature)" << endl | |
262 | 2818 << INDENT << " return signalId;" << endl; |
253 | 2819 } |
262 | 2820 |
253 | 2821 s << INDENT << "if (signalId < __signalSignatures.length)" << endl |
2822 << INDENT << " signature = __signalSignatures[signalId].ptr;" << endl | |
2823 << INDENT << "else" << endl | |
2824 << INDENT << " signalId -= __signalSignatures.length;" << endl | |
2825 << INDENT << "return signalId;" << endl; | |
1 | 2826 } |
2827 s << INDENT << "}" << endl; | |
2828 } | |
2829 | |
2830 void DGenerator::writeSignal(QTextStream &s, const AbstractMetaFunction *d_function) | |
2831 { | |
2832 Q_ASSERT(d_function->isSignal()); | |
2833 | |
2834 AbstractMetaArgumentList arguments = d_function->arguments(); | |
2835 int sz = arguments.count(); | |
2836 | |
2837 s << INDENT << "mixin Signal!(\"" << d_function->name() << "\""; | |
2838 | |
2839 if (sz > 0) { | |
2840 for (int i=0; i<sz; ++i) { | |
2841 s << ", "; | |
2842 | |
2843 QString modifiedType = d_function->typeReplaced(i+1); | |
2844 | |
2845 if (modifiedType.isEmpty()) | |
2846 s << translateType(arguments.at(i)->type(), d_function->implementingClass(), BoxedPrimitive); | |
2847 else | |
2848 s << modifiedType; | |
2849 } | |
2850 } | |
2851 | |
2852 s << ");" << endl; | |
2853 } | |
2854 | |
2855 void DGenerator::writeShellVirtualFunction(QTextStream &s, const AbstractMetaFunction *d_function, | |
2856 const AbstractMetaClass *implementor, int id) | |
2857 { | |
2858 Q_UNUSED(id); | |
2859 Q_UNUSED(implementor); | |
2860 | |
2861 s << "private extern(C) "; | |
2862 CppImplGenerator::writeVirtualDispatchFunction(s, d_function, true); | |
2863 s << "{" << endl; | |
2864 | |
2865 const AbstractMetaClass *own_class = d_function->ownerClass(); | |
2866 | |
2867 s << INDENT << "auto d_object = cast(" << own_class->name() << ") d_entity;" << endl; | |
2868 | |
2869 // the function arguments | |
2870 AbstractMetaArgumentList arguments = d_function->arguments(); | |
262 | 2871 foreach (const AbstractMetaArgument *argument, arguments) { |
1 | 2872 if (!d_function->argumentRemoved(argument->argumentIndex() + 1)) { |
2873 QString arg_name = argument->indexedName(); | |
2874 AbstractMetaType *type = argument->type(); | |
2875 // if has QString argument we have to pass char* and str.length to QString constructor | |
2876 { | |
2877 if(type->isEnum()) | |
2878 s << INDENT << "auto " << arg_name << "_enum = cast(" | |
2879 << type->typeEntry()->qualifiedTargetLangName() << ") " << arg_name << ";"; | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
2880 else if (type->typeEntry()->qualifiedCppName() == "QChar") |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
14
diff
changeset
|
2881 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
|
2882 << ") " << arg_name << ";"; |
1 | 2883 else if (type->isTargetLangString()) |
188 | 2884 s << INDENT << "string " << arg_name << "_d_ref = toUTF8(" |
1 | 2885 << arg_name << "[0.." << arg_name << "_size]);"; |
2886 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
|
2887 s << INDENT << "auto " << arg_name << "_d_qstr = QString(" << arg_name << ", true);" << endl |
1 | 2888 << INDENT << "string " << arg_name << "_d_ref = " << arg_name << "_d_qstr.toNativeString();"; |
257 | 2889 } |
1 | 2890 else if (type->typeEntry()->isStructInD()) |
2891 continue; | |
260 | 2892 else if (type->typeEntry()->isValue() || (type->typeEntry()->isValue() && type->isNativePointer())){ |
259 | 2893 s << INDENT << "scope " << arg_name << "_d_ref = new " << type->typeEntry()->name() << "(" << arg_name << ", QtdObjectFlags.skipNativeDelete);" << endl; |
262 | 2894 } |
257 | 2895 else if (!type->hasNativeId()) |
1 | 2896 continue; |
262 | 2897 else if (type->typeEntry()->isObject()) |
2898 { | |
259 | 2899 bool resetAfterUse = !type->isQObject() && d_function->resetObjectAfterUse(argument->argumentIndex() + 1); |
262 | 2900 |
310 | 2901 |
2902 if (resetAfterUse) | |
2903 s << INDENT << "auto " << arg_name << "_d_ref = scopeObject!(" << type->typeEntry()->name() << ")(" << arg_name << ");"; | |
259 | 2904 else |
2905 { | |
310 | 2906 s << INDENT << "auto " << arg_name << "_d_ref = " << type->typeEntry()->name() << ".__wrap(" << arg_name |
2907 << ");" << endl; | |
257 | 2908 } |
1 | 2909 } |
257 | 2910 else |
2911 qFatal(qPrintable(type->typeEntry()->name())); | |
262 | 2912 |
1 | 2913 s << endl; |
2914 } | |
262 | 2915 } |
1 | 2916 } |
2917 | |
2918 s << INDENT; | |
2919 AbstractMetaType *return_type = d_function->type(); | |
2920 QString new_return_type = QString(d_function->typeReplaced(0)).replace('$', '.'); | |
2921 bool has_return_type = new_return_type != "void" | |
2922 && (!new_return_type.isEmpty() || return_type != 0); | |
2923 if(has_return_type) { | |
2924 AbstractMetaType *f_type = d_function->type(); | |
262 | 2925 |
1 | 2926 if(f_type && (f_type->isObject() || f_type->isQObject() || f_type->isVariant() || |
2927 (f_type->isValue() && !f_type->typeEntry()->isStructInD()))) | |
2928 { | |
2929 QString f_type_name = f_type->name(); | |
2930 if(f_type->typeEntry()->designatedInterface()) | |
2931 f_type_name = f_type->typeEntry()->designatedInterface()->name(); | |
2932 s << f_type_name << " ret_value = "; | |
2933 } | |
2934 else if (f_type && f_type->isTargetLangString()) | |
2935 s << "string _d_str = "; | |
81 | 2936 else if (f_type && (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD())) |
1 | 2937 s << "*__d_return_value = "; |
2938 else | |
2939 s << "auto return_value = "; | |
2940 } | |
2941 s << "d_object." << d_function->name() << "("; | |
2942 | |
2943 uint nativeArgCount = 0; | |
2944 foreach (const AbstractMetaArgument *argument, arguments) | |
2945 if (!d_function->argumentRemoved(argument->argumentIndex() + 1)) { | |
2946 QString arg_name = argument->indexedName(); | |
2947 const AbstractMetaType *type = argument->type(); | |
2948 | |
2949 if (nativeArgCount > 0) | |
2950 s << "," << " "; | |
2951 | |
2952 QString modified_type = d_function->typeReplaced(argument->argumentIndex() + 1); | |
2953 if (!modified_type.isEmpty()) | |
2954 modified_type = modified_type.replace('$', '.'); | |
2955 | |
2956 if (modified_type == "string" /* && type->fullName() == "char" */) | |
2957 s << "fromStringz(" << arg_name << ")"; | |
2958 else { | |
2959 if(type->isContainer() | |
2960 || (type->isReference() && type->typeEntry()->isStructInD())) | |
2961 s << "*"; | |
2962 s << arg_name; | |
2963 } | |
2964 if (type->typeEntry()->isStructInD()) ; | |
2965 else if (type->isQObject() || type->isObject() | |
2966 || (type->typeEntry()->isValue() && type->isNativePointer()) | |
2967 || type->isValue() | |
2968 || type->isTargetLangString() || type->isVariant()) | |
2969 s << "_d_ref"; | |
2970 else if(type->isEnum()) | |
2971 s << "_enum"; | |
2972 | |
2973 nativeArgCount++; | |
2974 } | |
2975 s << ");" << endl; | |
2976 | |
2977 // check for arguments that may return value | |
2978 foreach (const AbstractMetaArgument *argument, arguments) | |
2979 if (!d_function->argumentRemoved(argument->argumentIndex() + 1)) { | |
2980 QString arg_name = argument->indexedName(); | |
2981 AbstractMetaType *type = argument->type(); | |
2982 | |
2983 if (type->typeEntry()->isValue() && type->isNativePointer() && type->typeEntry()->name() == "QString") | |
2984 s << INDENT << arg_name << "_d_qstr.assign(" << arg_name << "_d_ref);" << endl; | |
2985 } | |
2986 | |
2987 if(has_return_type) { | |
2988 AbstractMetaType *f_type = d_function->type(); | |
2989 if(f_type) { | |
2990 if(f_type->isObject() || f_type->isQObject() || f_type->isVariant() || | |
2991 (f_type->isValue() && !f_type->typeEntry()->isStructInD())) { | |
253 | 2992 QString native_id = "__nativeId"; |
1 | 2993 if (f_type->typeEntry()->designatedInterface()) |
2994 native_id = "__ptr_" + f_type->typeEntry()->designatedInterface()->name(); | |
2995 s << INDENT << "return ret_value is null? null : ret_value." << native_id << ";" << endl; | |
2996 } else if (f_type->isTargetLangString()) | |
104 | 2997 s << INDENT << "*ret_str = _d_str;" << endl; |
1 | 2998 else if (f_type->isContainer()) |
2999 s << INDENT << "*__d_arr_ptr = return_value.ptr;" << endl | |
3000 << INDENT << "*__d_arr_size = return_value.length;" << endl; | |
81 | 3001 else if (f_type->name() == "QModelIndex" || f_type->typeEntry()->isStructInD()) |
1 | 3002 ; |
3003 else | |
3004 s << INDENT << "return return_value;" << endl; | |
3005 } else | |
3006 s << INDENT << "return return_value;" << endl; | |
3007 | |
3008 } | |
3009 | |
3010 s << "}" << endl << endl; | |
3011 } | |
3012 | |
3013 void DGenerator::generate() | |
3014 { | |
257 | 3015 log = new QFile("arglog.txt"); |
3016 log->open(QFile::ReadWrite); | |
3017 logstream = new QTextStream(log); | |
1 | 3018 |
3019 Generator::generate(); | |
3020 | |
3021 { | |
3022 const AbstractMetaClass *last_class = 0; | |
3023 QFile file("mjb_nativepointer_api.log"); | |
3024 if (file.open(QFile::WriteOnly)) { | |
3025 QTextStream s(&file); | |
3026 | |
3027 AbstractMetaFunctionList nativepointer_functions; | |
3028 for (int i=0; i<m_nativepointer_functions.size(); ++i) { | |
3029 AbstractMetaFunction *f = const_cast<AbstractMetaFunction *>(m_nativepointer_functions[i]); | |
3030 if (f->ownerClass() == f->declaringClass() || f->isFinal()) | |
3031 nativepointer_functions.append(f); | |
3032 } | |
3033 | |
3034 s << "Number of public or protected functions with QNativePointer API: " << nativepointer_functions.size() << endl; | |
3035 foreach (const AbstractMetaFunction *f, nativepointer_functions) { | |
3036 if (last_class != f->ownerClass()) { | |
3037 last_class = f->ownerClass(); | |
3038 s << endl << endl<< "Class " << last_class->name() << ":" << endl; | |
3039 s << "---------------------------------------------------------------------------------" | |
3040 << endl; | |
3041 } | |
3042 | |
3043 s << f->minimalSignature() << endl; | |
3044 } | |
3045 | |
3046 m_nativepointer_functions.clear(); } | |
3047 } | |
3048 | |
3049 { | |
3050 const AbstractMetaClass *last_class = 0; | |
3051 QFile file("mjb_object_type_usage.log"); | |
3052 if (file.open(QFile::WriteOnly)) { | |
3053 QTextStream s(&file); | |
3054 | |
3055 AbstractMetaFunctionList resettable_object_functions; | |
3056 for (int i=0; i<m_resettable_object_functions.size(); ++i) { | |
3057 AbstractMetaFunction *f = const_cast<AbstractMetaFunction *>(m_resettable_object_functions[i]); | |
3058 if (f->ownerClass() == f->declaringClass() || f->isFinal()) | |
3059 resettable_object_functions.append(f); | |
3060 } | |
3061 | |
3062 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; | |
3063 foreach (const AbstractMetaFunction *f, resettable_object_functions) { | |
3064 if (last_class != f->ownerClass()) { | |
3065 last_class = f->ownerClass(); | |
3066 s << endl << endl<< "Class " << last_class->name() << ":" << endl; | |
3067 s << "---------------------------------------------------------------------------------" | |
3068 << endl; | |
3069 } | |
3070 | |
3071 s << f->minimalSignature() << endl; | |
3072 } | |
3073 | |
3074 m_resettable_object_functions.clear(); } | |
3075 } | |
3076 | |
3077 { | |
3078 QFile file("mjb_reference_count_candidates.log"); | |
3079 if (file.open(QFile::WriteOnly)) { | |
3080 QTextStream s(&file); | |
3081 | |
3082 s << "The following functions have a signature pattern which may imply that" << endl | |
3083 << "they need to apply reference counting to their arguments (" | |
3084 << m_reference_count_candidate_functions.size() << " functions) : " << endl; | |
3085 | |
3086 foreach (const AbstractMetaFunction *f, m_reference_count_candidate_functions) { | |
3087 s << f->implementingClass()->fullName() << " : " << f->minimalSignature() << endl; | |
3088 } | |
3089 } | |
3090 file.close(); | |
3091 } | |
262 | 3092 |
257 | 3093 delete logstream; |
3094 delete log; | |
1 | 3095 } |
3096 | |
3097 void DGenerator::writeFunctionAttributes(QTextStream &s, const AbstractMetaFunction *d_function, | |
3098 uint included_attributes, uint excluded_attributes, | |
3099 uint options) | |
3100 { | |
3101 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes; | |
3102 | |
3103 if ((attr & AbstractMetaAttributes::Public) || (attr & AbstractMetaAttributes::Protected)) { | |
3104 | |
3105 // Does the function use native pointer API? | |
3106 bool nativePointer = d_function->type() && d_function->type()->isNativePointer() | |
3107 && d_function->typeReplaced(0).isEmpty(); | |
3108 | |
3109 // Does the function need to be considered for resetting the Java objects after use? | |
3110 bool resettableObject = false; | |
3111 | |
3112 if (!nativePointer | |
3113 && d_function->type() | |
3114 && d_function->type()->hasInstantiations() | |
3115 && d_function->typeReplaced(0).isEmpty()) { | |
3116 | |
3117 QList<AbstractMetaType *> instantiations = d_function->type()->instantiations(); | |
3118 | |
3119 foreach (const AbstractMetaType *type, instantiations) { | |
3120 if (type && type->isNativePointer()) { | |
3121 nativePointer = true; | |
3122 break; | |
3123 } | |
3124 } | |
3125 | |
3126 } | |
3127 | |
3128 AbstractMetaArgumentList arguments = d_function->arguments(); | |
3129 if (!nativePointer || (!resettableObject && !d_function->isFinal())) { | |
3130 foreach (const AbstractMetaArgument *argument, arguments) { | |
3131 if (!d_function->argumentRemoved(argument->argumentIndex()+1) | |
3132 && d_function->typeReplaced(argument->argumentIndex()+1).isEmpty()) { | |
3133 | |
3134 if (argument->type()->isNativePointer()) { | |
3135 | |
3136 nativePointer = true; | |
3137 if (resettableObject) break ; | |
3138 | |
3139 } else if (!d_function->isFinalInTargetLang() | |
3140 && argument->type()->isObject() | |
3141 && !argument->type()->isQObject() | |
3142 && !d_function->resetObjectAfterUse(argument->argumentIndex()+1) | |
3143 && d_function->ownership(d_function->declaringClass(), TypeSystem::ShellCode, argument->argumentIndex()+1) == TypeSystem::InvalidOwnership) { | |
3144 | |
3145 resettableObject = true; | |
3146 if (nativePointer) break ; | |
3147 | |
3148 } else if (argument->type()->hasInstantiations()) { | |
3149 | |
3150 QList<AbstractMetaType *> instantiations = argument->type()->instantiations(); | |
3151 foreach (AbstractMetaType *type, instantiations) { | |
3152 if (type && type->isNativePointer()) { | |
3153 nativePointer = true; | |
3154 if (resettableObject) break; | |
3155 } else if (!d_function->isFinal() | |
3156 && type | |
3157 && type->isObject() | |
3158 && !type->isQObject() | |
3159 && !d_function->resetObjectAfterUse(argument->argumentIndex()+1)) { | |
3160 resettableObject = true; | |
3161 if (nativePointer) break ; | |
3162 } | |
3163 } | |
3164 | |
3165 if (nativePointer && resettableObject) | |
3166 break; | |
3167 | |
3168 } | |
3169 } | |
3170 } | |
3171 } | |
3172 | |
3173 if (nativePointer && !m_nativepointer_functions.contains(d_function)) | |
3174 m_nativepointer_functions.append(d_function); | |
3175 if (resettableObject && !m_resettable_object_functions.contains(d_function)) | |
3176 m_resettable_object_functions.append(d_function); | |
3177 } | |
3178 | |
3179 if ((options & SkipAttributes) == 0) { | |
3180 if (d_function->isEmptyFunction() | |
3181 || d_function->isDeprecated()) s << INDENT << "deprecated "; | |
3182 /* | |
3183 bool needsSuppressUnusedWarning = TypeDatabase::instance()->includeEclipseWarnings() | |
3184 && d_function->isSignal() | |
3185 && (((excluded_attributes & AbstractMetaAttributes::Private) == 0) | |
3186 && (d_function->isPrivate() | |
3187 || ((included_attributes & AbstractMetaAttributes::Private) != 0))); | |
3188 | |
3189 if (needsSuppressUnusedWarning && d_function->needsSuppressUncheckedWarning()) { | |
3190 s << INDENT<< "@SuppressWarnings({\"unchecked\", \"unused\"})" << endl; | |
3191 } else if (d_function->needsSuppressUncheckedWarning()) { | |
3192 s << INDENT<< "@SuppressWarnings(\"unchecked\")" << endl; | |
3193 } else if (needsSuppressUnusedWarning) { | |
3194 s << INDENT<< "@SuppressWarnings(\"unused\")" << endl; | |
3195 } | |
3196 | |
3197 if (!(attr & NoBlockedSlot) | |
3198 && !d_function->isConstructor() | |
3199 && !d_function->isSlot() | |
3200 && !d_function->isSignal() | |
3201 && !d_function->isStatic() | |
3202 && !(included_attributes & AbstractMetaAttributes::Static)) | |
3203 s << INDENT << "@QtBlockedSlot" << endl; | |
3204 */ | |
3205 if (!(options & ExternC)) | |
3206 s << INDENT; | |
3207 | |
3208 if (attr & AbstractMetaAttributes::Public) s << "public "; | |
3209 else if (attr & AbstractMetaAttributes::Protected) s << "protected "; | |
3210 else if (attr & AbstractMetaAttributes::Private) s << "private "; | |
3211 else if (attr & AbstractMetaAttributes::Native) s << "private extern(C) "; | |
3212 bool isStatic = (attr & AbstractMetaAttributes::Static); | |
3213 | |
3214 if (attr & AbstractMetaAttributes::Native) ; | |
3215 else if (!isStatic && (attr & AbstractMetaAttributes::FinalInTargetLang)) s << "final "; | |
3216 else if (!isStatic && (attr & AbstractMetaAttributes::Abstract)) s << "abstract "; | |
3217 | |
3218 if (isStatic && !(options & ExternC)) s << "static "; | |
3219 } | |
3220 | |
3221 if ((options & SkipReturnType) == 0) { | |
3222 QString modified_type = d_function->typeReplaced(0); | |
3223 if (options & ExternC) { | |
3224 uint options = 0x0004; // qtd externC | |
3225 s << CppImplGenerator::jniReturnName(d_function, options, true) << " "; | |
3226 } | |
3227 else if (modified_type.isEmpty()) | |
3228 s << translateType(d_function->type(), d_function->implementingClass(), (Option) options); | |
3229 else | |
3230 s << modified_type.replace('$', '.'); | |
3231 s << " "; | |
3232 } | |
3233 | |
3234 } | |
3235 | |
3236 void DGenerator::writeConstructorContents(QTextStream &s, const AbstractMetaFunction *d_function) | |
3237 { | |
3238 // Write constructor | |
3239 s << " {" << endl; | |
3240 { | |
3241 Indentation indent(INDENT); | |
3242 bool shellClass = d_function->ownerClass()->generateShellClass(); | |
223 | 3243 |
1 | 3244 writeJavaCallThroughContents(s, d_function); |
3245 | |
3246 // Write out expense checks if present... | |
3247 const AbstractMetaClass *d_class = d_function->implementingClass(); | |
3248 const ComplexTypeEntry *te = d_class->typeEntry(); | |
3249 if (te->expensePolicy().isValid()) { | |
3250 s << endl; | |
3251 const ExpensePolicy &ep = te->expensePolicy(); | |
3252 s << INDENT << "qt.GeneratorUtilities.countExpense(" << d_class->fullName() | |
3253 << ".class, " << ep.cost << ", " << ep.limit << ");" << endl; | |
3254 } | |
3255 | |
3256 foreach (CodeSnip snip, te->codeSnips()) { | |
3257 if (snip.language == TypeSystem::Constructors) { | |
3258 snip.formattedCode(s, INDENT); | |
3259 } | |
3260 } | |
3261 | |
253 | 3262 s << INDENT << "this(ret);" << endl; |
1 | 3263 } |
3264 s << INDENT << "}" << endl << endl; | |
3265 | |
3266 /* qtd // Write native constructor | |
3267 if (d_function->jumpTableId() == -1) | |
3268 writePrivateNativeFunction(s, d_function); | |
3269 */ | |
3270 } | |
3271 | |
3272 void DGenerator::writeFunctionArguments(QTextStream &s, const AbstractMetaFunction *d_function, | |
3273 int argument_count, uint options) | |
3274 { | |
3275 AbstractMetaArgumentList arguments = d_function->arguments(); | |
3276 | |
3277 if (argument_count == -1) | |
3278 argument_count = arguments.size(); | |
3279 | |
3280 for (int i=0; i<argument_count; ++i) { | |
3281 if (!d_function->argumentRemoved(i+1)) { | |
3282 if (i != 0) | |
3283 s << ", "; | |
3284 writeArgument(s, d_function, arguments.at(i), options); | |
3285 } | |
3286 } | |
3287 } | |
3288 | |
3289 | |
3290 void DGenerator::writeExtraFunctions(QTextStream &s, const AbstractMetaClass *d_class) | |
3291 { | |
3292 const ComplexTypeEntry *class_type = d_class->typeEntry(); | |
3293 Q_ASSERT(class_type); | |
3294 | |
3295 CodeSnipList code_snips = class_type->codeSnips(); | |
3296 foreach (const CodeSnip &snip, code_snips) { | |
3297 if ((!d_class->isInterface() && snip.language == TypeSystem::TargetLangCode) | |
3298 || (d_class->isInterface() && snip.language == TypeSystem::Interface)) { | |
3299 s << endl; | |
3300 snip.formattedCode(s, INDENT); | |
3301 } | |
3302 } | |
3303 } | |
3304 | |
3305 | |
3306 void DGenerator::writeToStringFunction(QTextStream &s, const AbstractMetaClass *d_class) | |
3307 { | |
3308 bool generate = d_class->hasToStringCapability() && !d_class->hasDefaultToStringFunction(); | |
3309 bool core = d_class->package() == QLatin1String("qt.core"); | |
3310 bool qevent = false; | |
3311 | |
3312 const AbstractMetaClass *cls = d_class; | |
3313 while (cls) { | |
3314 if (cls->name() == "QEvent") { | |
3315 qevent = true; | |
3316 break; | |
3317 } | |
3318 cls = cls->baseClass(); | |
3319 } | |
3320 | |
3321 if (generate || qevent) { | |
3322 | |
3323 if (qevent && core) { | |
3324 s << endl | |
3325 << " @Override" << endl | |
3326 << " public String toString() {" << endl | |
3327 << " return getClass().getSimpleName() + \"(type=\" + type().name() + \")\";" << endl | |
3328 << " }" << endl; | |
3329 } else { | |
3330 s << endl | |
3331 << " @Override" << endl | |
3332 << " public String toString() {" << endl | |
253 | 3333 << " if (__nativeId == 0)" << endl |
1 | 3334 << " throw new QNoNativeResourcesException(\"Function call on incomplete object of type: \" +getClass().getName());" << endl |
3335 << " return __qt_toString(nativeId());" << endl | |
3336 << " }" << endl | |
3337 << " native String __qt_toString(long __this_nativeId);" << endl; | |
3338 } | |
3339 } | |
3340 } | |
3341 | |
3342 void DGenerator::writeCloneFunction(QTextStream &s, const AbstractMetaClass *d_class) | |
3343 { | |
3344 s << endl | |
3345 << " @Override" << endl | |
3346 << " public " << d_class->name() << " clone() {" << endl | |
3347 << " if (nativeId() == 0)" << endl | |
3348 << " throw new QNoNativeResourcesException(\"Function call on incomplete object of type: \" +getClass().getName());" << endl | |
3349 << " return __qt_clone(nativeId());" << endl | |
3350 << " }" << endl | |
3351 << " native " << d_class->name() << " __qt_clone(long __this_nativeId);" << endl; | |
3352 } | |
3353 | |
3354 ClassFromEntry* ClassFromEntry::m_instance = NULL; | |
3355 | |
3356 ClassFromEntry::ClassFromEntry() | |
3357 { | |
110 | 3358 } |
3359 | |
3360 AbstractMetaClass* ClassFromEntry::get(const TypeEntry *ctype) | |
3361 { | |
3362 if(!m_instance) | |
3363 return NULL; | |
3364 | |
3365 return m_instance->classFromEntry[ctype]; | |
3366 } | |
3367 | |
3368 void ClassFromEntry::construct(const AbstractMetaClassList &classes) | |
3369 { | |
3370 if(!m_instance) { | |
3371 m_instance = new ClassFromEntry; | |
3372 m_instance->setClasses(classes); | |
3373 m_instance->buildHash(); | |
3374 } | |
3375 } | |
3376 | |
3377 void ClassFromEntry::buildHash() | |
3378 { | |
1 | 3379 foreach (AbstractMetaClass *cls, m_classes) { |
3380 const ComplexTypeEntry *ctype = cls->typeEntry(); | |
3381 classFromEntry[ctype] = cls; | |
3382 } | |
3383 } | |
3384 | |
110 | 3385 void ClassFromEntry::print(QTextStream &s) |
1 | 3386 { |
110 | 3387 s << "_fuck_" << m_instance->m_classes.size(); |
3388 foreach (AbstractMetaClass *cls, m_instance->m_classes) { | |
3389 s << cls->name() << endl; | |
3390 } | |
1 | 3391 } |
110 | 3392 |