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