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 "abstractmetalang.h"
|
|
43 #include "reporthandler.h"
|
|
44 #include "jumptable.h"
|
257
|
45 #include <iostream>
|
1
|
46
|
|
47 /*******************************************************************************
|
|
48 * AbstractMetaType
|
|
49 */
|
|
50 AbstractMetaType *AbstractMetaType::copy() const
|
|
51 {
|
|
52 AbstractMetaType *cpy = new AbstractMetaType;
|
|
53
|
|
54 cpy->setTypeUsagePattern(typeUsagePattern());
|
|
55 cpy->setConstant(isConstant());
|
|
56 cpy->setReference(isReference());
|
|
57 cpy->setIndirections(indirections());
|
|
58 cpy->setInstantiations(instantiations());
|
|
59 cpy->setArrayElementCount(arrayElementCount());
|
|
60 cpy->setOriginalTypeDescription(originalTypeDescription());
|
|
61 cpy->setOriginalTemplateType(originalTemplateType() ? originalTemplateType()->copy() : 0);
|
|
62
|
|
63 cpy->setArrayElementType(arrayElementType() ? arrayElementType()->copy() : 0);
|
|
64
|
|
65 cpy->setTypeEntry(typeEntry());
|
|
66
|
|
67 return cpy;
|
|
68 }
|
|
69
|
|
70 QString AbstractMetaType::cppSignature() const
|
|
71 {
|
|
72 QString s;
|
|
73
|
|
74 if (isConstant())
|
|
75 s += "const ";
|
|
76
|
|
77 s += typeEntry()->qualifiedCppName();
|
|
78
|
|
79 if (hasInstantiationInCpp()) {
|
|
80 QList<AbstractMetaType *> types = instantiations();
|
|
81 s += "<";
|
|
82 for (int i=0; i<types.count(); ++i) {
|
|
83 if (i > 0)
|
|
84 s += ", ";
|
|
85 s += types.at(i)->cppSignature();
|
|
86 }
|
|
87 s += " >";
|
|
88 }
|
|
89
|
|
90 if (actualIndirections()) {
|
|
91 s += ' ';
|
|
92 if (indirections())
|
|
93 s += QString(indirections(), '*');
|
|
94 if (isReference())
|
|
95 s += '&';
|
|
96 }
|
|
97 return s;
|
|
98 }
|
|
99
|
|
100 /*******************************************************************************
|
|
101 * AbstractMetaArgument
|
|
102 */
|
|
103 AbstractMetaArgument *AbstractMetaArgument::copy() const
|
|
104 {
|
|
105 AbstractMetaArgument *cpy = new AbstractMetaArgument;
|
|
106 cpy->setName(AbstractMetaVariable::name());
|
|
107 cpy->setDefaultValueExpression(defaultValueExpression());
|
|
108 cpy->setType(type()->copy());
|
|
109 cpy->setArgumentIndex(argumentIndex());
|
|
110
|
|
111 return cpy;
|
|
112 }
|
|
113
|
|
114
|
|
115 QString AbstractMetaArgument::argumentName() const
|
|
116 {
|
|
117 QString n = AbstractMetaVariable::name();
|
|
118 // replace for arguments which are D keywords such as "version"
|
|
119 n = ArgumentReplace::translate(n);
|
|
120
|
|
121 if (n.isEmpty()) {
|
|
122 return QString("arg__%2").arg(m_argument_index + 1);
|
|
123 }
|
|
124 return n;
|
|
125 }
|
|
126
|
|
127
|
|
128 QString AbstractMetaArgument::indexedName() const
|
|
129 {
|
|
130 QString n = AbstractMetaVariable::name();
|
|
131 if (n.isEmpty())
|
|
132 return argumentName();
|
|
133 return QString("%1%2").arg(n).arg(m_argument_index);
|
|
134 }
|
|
135
|
|
136 QString AbstractMetaArgument::name() const
|
|
137 {
|
|
138 Q_ASSERT_X(0, "AbstractMetaArgument::name()", "use argumentName() or indexedName() instead");
|
|
139 return QString();
|
|
140 }
|
|
141
|
|
142
|
|
143 /*******************************************************************************
|
|
144 * AbstractMetaFunction
|
|
145 */
|
|
146 AbstractMetaFunction::~AbstractMetaFunction()
|
|
147 {
|
|
148 qDeleteAll(m_arguments);
|
|
149 delete m_type;
|
|
150 }
|
|
151
|
|
152 /*******************************************************************************
|
|
153 * Indicates that this function has a modification that removes it
|
|
154 */
|
|
155 bool AbstractMetaFunction::isModifiedRemoved(int types) const
|
|
156 {
|
|
157 FunctionModificationList mods = modifications(implementingClass());
|
|
158 foreach (FunctionModification mod, mods) {
|
|
159 if (!mod.isRemoveModifier())
|
|
160 continue;
|
|
161
|
|
162 if ((mod.removal & types) == types)
|
|
163 return true;
|
|
164 }
|
|
165
|
|
166 return false;
|
|
167 }
|
|
168
|
|
169 bool AbstractMetaFunction::needsCallThrough() const
|
|
170 {
|
|
171 if (ownerClass()->isInterface())
|
|
172 return false;
|
|
173 if (referenceCounts(implementingClass()).size() > 0)
|
|
174 return true;
|
|
175 if (argumentsHaveNativeId() || !isStatic())
|
|
176 return true;
|
|
177 if (JumpTableGenerator::isJumpTableActive())
|
|
178 return true;
|
|
179
|
|
180 foreach (const AbstractMetaArgument *arg, arguments()) {
|
|
181 if (arg->type()->isArray() || arg->type()->isTargetLangEnum() || arg->type()->isTargetLangFlags())
|
|
182 return true;
|
|
183 }
|
|
184
|
|
185 if (type() && (type()->isArray() || type()->isTargetLangEnum() || type()->isTargetLangFlags()))
|
|
186 return true;
|
|
187
|
|
188 for (int i=-1; i<=arguments().size(); ++i) {
|
|
189 TypeSystem::Ownership owner = this->ownership(implementingClass(), TypeSystem::TargetLangCode, i);
|
|
190 if (owner != TypeSystem::InvalidOwnership)
|
|
191 return true;
|
|
192 }
|
|
193
|
|
194 return false;
|
|
195 }
|
|
196
|
|
197 bool AbstractMetaFunction::needsSuppressUncheckedWarning() const
|
|
198 {
|
|
199 for (int i=-1; i<=arguments().size(); ++i) {
|
|
200 QList<ReferenceCount> referenceCounts = this->referenceCounts(implementingClass(), i);
|
|
201 foreach (ReferenceCount referenceCount, referenceCounts) {
|
|
202 if (referenceCount.action != ReferenceCount::Set)
|
|
203 return true;
|
|
204 }
|
|
205 }
|
|
206 return false;
|
|
207 }
|
|
208
|
|
209 QString AbstractMetaFunction::marshalledName(bool classIsOwner) const
|
|
210 {
|
|
211 QString returned = "qtd_";
|
|
212 if(classIsOwner)
|
|
213 returned += ownerClass()->name();
|
|
214 else
|
|
215 returned += declaringClass()->name();
|
|
216
|
|
217 returned += "_" + name();
|
|
218 AbstractMetaArgumentList arguments = this->arguments();
|
|
219 foreach (const AbstractMetaArgument *arg, arguments) {
|
|
220 returned += "_";
|
|
221 if (arg->type()->isNativePointer()) {
|
|
222 returned += "nativepointer" + arg->type()->name().replace("[]", "_3").replace(".", "_");
|
|
223 } else if (arg->type()->isIntegerEnum() || arg->type()->isIntegerFlags()) {
|
|
224 returned += "int";
|
|
225 } else {
|
|
226 returned += arg->type()->name().replace("[]", "_3").replace(".", "_");
|
|
227 }
|
|
228 }
|
|
229 return returned;
|
|
230 }
|
|
231
|
|
232 bool AbstractMetaFunction::operator<(const AbstractMetaFunction &other) const
|
|
233 {
|
|
234 uint result = compareTo(&other);
|
|
235 return result & NameLessThan;
|
|
236 }
|
|
237
|
|
238
|
|
239 /*!
|
|
240 Returns a mask of CompareResult describing how this function is
|
|
241 compares to another function
|
|
242 */
|
|
243 uint AbstractMetaFunction::compareTo(const AbstractMetaFunction *other) const
|
|
244 {
|
|
245 uint result = 0;
|
|
246
|
|
247 // Enclosing class...
|
|
248 if (ownerClass() == other->ownerClass()) {
|
|
249 result |= EqualImplementor;
|
|
250 }
|
|
251
|
|
252 // Attributes
|
|
253 if (attributes() == other->attributes()) {
|
|
254 result |= EqualAttributes;
|
|
255 }
|
|
256
|
|
257 // Compare types
|
|
258 AbstractMetaType *t = type();
|
|
259 AbstractMetaType *ot = other->type();
|
|
260 if ((!t && !ot) || ((t && ot && t->name() == ot->name()))) {
|
|
261 result |= EqualReturnType;
|
|
262 }
|
|
263
|
|
264 // Compare names
|
|
265 int cmp = originalName().compare(other->originalName());
|
|
266
|
|
267 if (cmp < 0) {
|
|
268 result |= NameLessThan;
|
|
269 } else if (cmp == 0) {
|
|
270 result |= EqualName;
|
|
271 }
|
|
272
|
|
273 // compare name after modification...
|
|
274 cmp = modifiedName().compare(other->modifiedName());
|
|
275 if (cmp == 0)
|
|
276 result |= EqualModifiedName;
|
|
277
|
|
278 // Compare arguments...
|
|
279 AbstractMetaArgumentList min_arguments;
|
|
280 AbstractMetaArgumentList max_arguments;
|
|
281 if (arguments().size() < other->arguments().size()) {
|
|
282 min_arguments = arguments();
|
|
283 max_arguments = other->arguments();
|
|
284 } else {
|
|
285 min_arguments = other->arguments();
|
|
286 max_arguments = arguments();
|
|
287 }
|
|
288
|
|
289 int min_count = min_arguments.size();
|
|
290 int max_count = max_arguments.size();
|
|
291 bool same = true;
|
|
292 for (int i=0; i<max_count; ++i) {
|
|
293 if (i < min_count) {
|
|
294 const AbstractMetaArgument *min_arg = min_arguments.at(i);
|
|
295 const AbstractMetaArgument *max_arg = max_arguments.at(i);
|
|
296 if (min_arg->type()->name() != max_arg->type()->name()
|
|
297 && (min_arg->defaultValueExpression().isEmpty() || max_arg->defaultValueExpression().isEmpty())) {
|
|
298 same = false;
|
|
299 break;
|
|
300 }
|
|
301 } else {
|
|
302 if (max_arguments.at(i)->defaultValueExpression().isEmpty()) {
|
|
303 same = false;
|
|
304 break;
|
|
305 }
|
|
306 }
|
|
307 }
|
|
308
|
|
309 if (same)
|
|
310 result |= min_count == max_count ? EqualArguments : EqualDefaultValueOverload;
|
|
311
|
|
312 return result;
|
|
313 }
|
|
314
|
|
315 AbstractMetaFunction *AbstractMetaFunction::copy() const
|
|
316 {
|
|
317 AbstractMetaFunction *cpy = new AbstractMetaFunction;
|
|
318 cpy->setName(name());
|
|
319 cpy->setOriginalName(originalName());
|
|
320 cpy->setOwnerClass(ownerClass());
|
|
321 cpy->setImplementingClass(implementingClass());
|
|
322 cpy->setInterfaceClass(interfaceClass());
|
|
323 cpy->setFunctionType(functionType());
|
|
324 cpy->setAttributes(attributes());
|
|
325 cpy->setDeclaringClass(declaringClass());
|
|
326 if (type())
|
|
327 cpy->setType(type()->copy());
|
|
328 cpy->setConstant(isConstant());
|
|
329 cpy->setOriginalAttributes(originalAttributes());
|
|
330
|
|
331 foreach (AbstractMetaArgument *arg, arguments())
|
|
332 cpy->addArgument(arg->copy());
|
|
333
|
|
334 Q_ASSERT((!type() && !cpy->type())
|
|
335 || (type()->instantiations() == cpy->type()->instantiations()));
|
|
336
|
|
337 return cpy;
|
|
338 }
|
|
339
|
|
340 QStringList AbstractMetaFunction::introspectionCompatibleSignatures(const QStringList &resolvedArguments) const
|
|
341 {
|
|
342 AbstractMetaArgumentList arguments = this->arguments();
|
|
343 if (arguments.size() == resolvedArguments.size()) {
|
|
344 return (QStringList() << QMetaObject::normalizedSignature((name() + "(" + resolvedArguments.join(",") + ")").toUtf8().constData()));
|
|
345 } else {
|
|
346 QStringList returned;
|
|
347
|
|
348 AbstractMetaArgument *argument = arguments.at(resolvedArguments.size());
|
|
349 QStringList minimalTypeSignature = argument->type()->minimalSignature().split("::");
|
|
350 for (int i=0; i<minimalTypeSignature.size(); ++i) {
|
|
351 returned += introspectionCompatibleSignatures(QStringList(resolvedArguments)
|
|
352 << QStringList(minimalTypeSignature.mid(minimalTypeSignature.size() - i - 1)).join("::"));
|
|
353 }
|
|
354
|
|
355 return returned;
|
|
356 }
|
|
357 }
|
|
358
|
|
359 QString AbstractMetaFunction::signature() const
|
|
360 {
|
|
361 QString s(m_original_name);
|
|
362
|
|
363 s += "(";
|
|
364
|
|
365 for (int i=0; i<m_arguments.count(); ++i) {
|
|
366 if (i > 0)
|
|
367 s += ", ";
|
|
368 AbstractMetaArgument *a = m_arguments.at(i);
|
|
369 s += a->type()->cppSignature();
|
|
370
|
|
371 // We need to have the argument names in the qdoc files
|
|
372 s += " ";
|
|
373 s += a->argumentName();
|
|
374 }
|
|
375 s += ")";
|
|
376
|
|
377 if (isConstant())
|
|
378 s += " const";
|
|
379
|
|
380 return s;
|
|
381 }
|
|
382
|
|
383 int AbstractMetaFunction::actualMinimumArgumentCount() const
|
|
384 {
|
|
385 AbstractMetaArgumentList arguments = this->arguments();
|
|
386
|
|
387 int count = 0;
|
|
388 for (int i=0; i<arguments.size(); ++i && ++count) {
|
|
389 if (argumentRemoved(i + 1)) --count;
|
|
390 else if (!arguments.at(i)->defaultValueExpression().isEmpty()) break;
|
|
391 }
|
|
392
|
|
393 return count;
|
|
394 }
|
|
395
|
|
396 // Returns reference counts for argument at idx, or all arguments if idx == -2
|
|
397 QList<ReferenceCount> AbstractMetaFunction::referenceCounts(const AbstractMetaClass *cls, int idx) const
|
|
398 {
|
|
399 QList<ReferenceCount> returned;
|
|
400
|
|
401 FunctionModificationList mods = this->modifications(cls);
|
|
402 foreach (FunctionModification mod, mods) {
|
|
403 QList<ArgumentModification> argument_mods = mod.argument_mods;
|
|
404 foreach (ArgumentModification argument_mod, argument_mods) {
|
|
405 if (argument_mod.index != idx && idx != -2)
|
|
406 continue;
|
|
407 returned += argument_mod.referenceCounts;
|
|
408 }
|
|
409 }
|
|
410
|
|
411 return returned;
|
|
412 }
|
|
413
|
|
414 QString AbstractMetaFunction::replacedDefaultExpression(const AbstractMetaClass *cls, int key) const
|
|
415 {
|
|
416 FunctionModificationList modifications = this->modifications(cls);
|
|
417 foreach (FunctionModification modification, modifications) {
|
|
418 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
419 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
420 if (argument_modification.index == key
|
|
421 && !argument_modification.replaced_default_expression.isEmpty()) {
|
|
422 return argument_modification.replaced_default_expression;
|
|
423 }
|
|
424 }
|
|
425 }
|
|
426
|
|
427 return QString();
|
|
428 }
|
|
429
|
|
430 bool AbstractMetaFunction::removedDefaultExpression(const AbstractMetaClass *cls, int key) const
|
|
431 {
|
|
432 FunctionModificationList modifications = this->modifications(cls);
|
|
433 foreach (FunctionModification modification, modifications) {
|
|
434 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
435 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
436 if (argument_modification.index == key
|
|
437 && argument_modification.removed_default_expression) {
|
|
438 return true;
|
|
439 }
|
|
440 }
|
|
441 }
|
|
442
|
|
443 return false;
|
|
444 }
|
|
445
|
|
446 bool AbstractMetaFunction::resetObjectAfterUse(int argument_idx) const
|
|
447 {
|
|
448 const AbstractMetaClass *cls = declaringClass();
|
|
449 FunctionModificationList modifications = this->modifications(cls);
|
|
450 foreach (FunctionModification modification, modifications) {
|
|
451 QList<ArgumentModification> argumentModifications = modification.argument_mods;
|
|
452 foreach (ArgumentModification argumentModification, argumentModifications) {
|
|
453 if (argumentModification.index == argument_idx && argumentModification.reset_after_use)
|
|
454 return true;
|
|
455 }
|
|
456 }
|
|
457
|
|
458 return false;
|
|
459 }
|
|
460
|
|
461 QString AbstractMetaFunction::nullPointerDefaultValue(const AbstractMetaClass *mainClass, int argument_idx) const
|
|
462 {
|
|
463 Q_ASSERT(nullPointersDisabled(mainClass, argument_idx));
|
|
464
|
|
465 const AbstractMetaClass *cls = mainClass;
|
|
466 if (cls == 0)
|
|
467 cls = implementingClass();
|
|
468
|
|
469 do {
|
|
470 FunctionModificationList modifications = this->modifications(cls);
|
|
471 foreach (FunctionModification modification, modifications) {
|
|
472 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
473 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
474 if (argument_modification.index == argument_idx
|
|
475 && argument_modification.no_null_pointers) {
|
|
476 return argument_modification.null_pointer_default_value;
|
|
477 }
|
|
478 }
|
|
479 }
|
|
480
|
|
481 cls = cls->baseClass();
|
|
482 } while (cls != 0 && mainClass == 0); // Once when mainClass != 0, or once for all base classes of implementing class
|
|
483
|
|
484 return QString();
|
|
485
|
|
486 }
|
|
487
|
|
488 bool AbstractMetaFunction::nullPointersDisabled(const AbstractMetaClass *mainClass, int argument_idx) const
|
|
489 {
|
|
490 const AbstractMetaClass *cls = mainClass;
|
|
491 if (cls == 0)
|
|
492 cls = implementingClass();
|
|
493
|
|
494 do {
|
|
495 FunctionModificationList modifications = this->modifications(cls);
|
|
496 foreach (FunctionModification modification, modifications) {
|
|
497 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
498 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
499 if (argument_modification.index == argument_idx
|
|
500 && argument_modification.no_null_pointers) {
|
|
501 return true;
|
|
502 }
|
|
503 }
|
|
504 }
|
|
505
|
|
506 cls = cls->baseClass();
|
|
507 } while (cls != 0 && mainClass == 0); // Once when mainClass != 0, or once for all base classes of implementing class
|
|
508
|
|
509 return false;
|
|
510 }
|
|
511
|
|
512 QString AbstractMetaFunction::conversionRule(TypeSystem::Language language, int key) const
|
|
513 {
|
|
514 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
515 foreach (FunctionModification modification, modifications) {
|
|
516 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
517 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
518 if (argument_modification.index != key)
|
|
519 continue;
|
|
520
|
|
521 foreach (CodeSnip snip, argument_modification.conversion_rules) {
|
|
522 if (snip.language == language && !snip.code().isEmpty())
|
|
523 return snip.code();
|
|
524 }
|
|
525 }
|
|
526 }
|
|
527
|
|
528 return QString();
|
|
529 }
|
|
530
|
|
531 QString AbstractMetaFunction::argumentReplaced(int key) const
|
|
532 {
|
|
533 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
534 foreach (FunctionModification modification, modifications) {
|
|
535 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
536 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
537 if (argument_modification.index == key && !argument_modification.replace_value.isEmpty()) {
|
|
538 return argument_modification.replace_value;
|
|
539 }
|
|
540 }
|
|
541 }
|
|
542
|
|
543 return "";
|
|
544 }
|
|
545
|
|
546 bool AbstractMetaFunction::argumentRemoved(int key) const
|
|
547 {
|
|
548 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
549 foreach (FunctionModification modification, modifications) {
|
|
550 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
551 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
552 if (argument_modification.index == key) {
|
|
553 if (argument_modification.removed) {
|
|
554 return true;
|
|
555 }
|
|
556 }
|
|
557 }
|
|
558 }
|
|
559
|
|
560 return false;
|
|
561 }
|
|
562
|
|
563 bool AbstractMetaFunction::storeResult() const
|
|
564 {
|
|
565 if (m_store_result == 2)
|
|
566 return true;
|
|
567 else
|
|
568 return false;
|
|
569 }
|
|
570
|
|
571 void AbstractMetaFunction::checkStoreResult()
|
|
572 {
|
|
573 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
574 foreach (FunctionModification modification, modifications) {
|
|
575 if (modification.store_result) {
|
|
576 m_store_result = 2;
|
|
577 return;
|
|
578 }
|
|
579 }
|
|
580
|
|
581 m_store_result = 1;
|
|
582 }
|
|
583
|
|
584 bool AbstractMetaFunction::isVirtualSlot() const
|
|
585 {
|
|
586 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
587 foreach (FunctionModification modification, modifications) {
|
|
588 if (modification.isVirtualSlot())
|
|
589 return true;
|
|
590 }
|
|
591
|
|
592 return false;
|
|
593 }
|
|
594
|
|
595 bool AbstractMetaFunction::disabledGarbageCollection(const AbstractMetaClass *cls, int key) const
|
|
596 {
|
|
597 FunctionModificationList modifications = this->modifications(cls);
|
|
598 foreach (FunctionModification modification, modifications) {
|
|
599 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
600 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
601 if (argument_modification.index != key)
|
|
602 continue;
|
|
603
|
|
604 foreach (TypeSystem::Ownership ownership, argument_modification.ownerships.values()) {
|
|
605 if (ownership == TypeSystem::CppOwnership)
|
|
606 return true;
|
|
607 }
|
|
608
|
|
609 }
|
|
610 }
|
|
611
|
|
612 return false;
|
|
613 }
|
|
614
|
|
615 bool AbstractMetaFunction::isDeprecated() const
|
|
616 {
|
|
617 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
618 foreach (FunctionModification modification, modifications) {
|
|
619 if (modification.isDeprecated())
|
|
620 return true;
|
|
621 }
|
|
622 return false;
|
|
623 }
|
|
624
|
|
625 TypeSystem::Ownership AbstractMetaFunction::ownership(const AbstractMetaClass *cls, TypeSystem::Language language, int key) const
|
|
626 {
|
|
627 FunctionModificationList modifications = this->modifications(cls);
|
|
628 foreach (FunctionModification modification, modifications) {
|
|
629 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
630 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
631 if (argument_modification.index == key)
|
|
632 return argument_modification.ownerships.value(language, TypeSystem::InvalidOwnership);
|
|
633 }
|
|
634 }
|
|
635
|
|
636 return TypeSystem::InvalidOwnership;
|
|
637 }
|
|
638
|
|
639 bool AbstractMetaFunction::isRemovedFromAllLanguages(const AbstractMetaClass *cls) const
|
|
640 {
|
|
641 return isRemovedFrom(cls, TypeSystem::All);
|
|
642 }
|
|
643
|
|
644 bool AbstractMetaFunction::isRemovedFrom(const AbstractMetaClass *cls, TypeSystem::Language language) const
|
|
645 {
|
|
646 FunctionModificationList modifications = this->modifications(cls);
|
|
647 foreach (FunctionModification modification, modifications) {
|
|
648 if ((modification.removal & language) == language)
|
|
649 return true;
|
|
650 }
|
|
651
|
|
652 return false;
|
|
653
|
|
654 }
|
|
655
|
|
656 QString AbstractMetaFunction::typeReplaced(int key) const
|
|
657 {
|
|
658 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
659 foreach (FunctionModification modification, modifications) {
|
|
660 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
661 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
662 if (argument_modification.index == key
|
|
663 && !argument_modification.modified_type.isEmpty()) {
|
|
664 return argument_modification.modified_type;
|
|
665 }
|
|
666 }
|
|
667 }
|
|
668
|
|
669 return QString();
|
|
670 }
|
|
671
|
|
672 QString AbstractMetaFunction::minimalSignature() const
|
|
673 {
|
|
674 if (!m_cached_minimal_signature.isEmpty())
|
|
675 return m_cached_minimal_signature;
|
|
676
|
|
677 QString minimalSignature = originalName() + "(";
|
|
678 AbstractMetaArgumentList arguments = this->arguments();
|
|
679
|
|
680 for (int i=0; i<arguments.count(); ++i) {
|
|
681 AbstractMetaType *t = arguments.at(i)->type();
|
|
682
|
|
683 if (i > 0)
|
|
684 minimalSignature += ",";
|
|
685
|
|
686 minimalSignature += t->minimalSignature();
|
|
687 }
|
|
688 minimalSignature += ")";
|
|
689 if (isConstant())
|
|
690 minimalSignature += "const";
|
|
691
|
|
692 minimalSignature = QMetaObject::normalizedSignature(minimalSignature.toLocal8Bit().constData());
|
|
693 m_cached_minimal_signature = minimalSignature;
|
|
694
|
|
695 return minimalSignature;
|
|
696 }
|
|
697
|
|
698 FunctionModificationList AbstractMetaFunction::modifications(const AbstractMetaClass *implementor) const
|
|
699 {
|
|
700 Q_ASSERT(implementor);
|
|
701 return implementor->typeEntry()->functionModifications(minimalSignature());
|
|
702 }
|
|
703
|
|
704 bool AbstractMetaFunction::hasModifications(const AbstractMetaClass *implementor) const
|
|
705 {
|
|
706 FunctionModificationList mods = modifications(implementor);
|
|
707 return mods.count() > 0;
|
|
708 }
|
|
709
|
|
710 QString AbstractMetaFunction::modifiedName() const
|
|
711 {
|
|
712 if (m_cached_modified_name.isEmpty()) {
|
|
713 FunctionModificationList mods = modifications(implementingClass());
|
|
714 foreach (FunctionModification mod, mods) {
|
|
715 if (mod.isRenameModifier()) {
|
|
716 m_cached_modified_name = mod.renamedToName;
|
|
717 break;
|
|
718 }
|
|
719 }
|
|
720 if (m_cached_modified_name.isEmpty())
|
|
721 m_cached_modified_name = name();
|
|
722 }
|
|
723 return m_cached_modified_name;
|
|
724 }
|
|
725
|
|
726 QString AbstractMetaFunction::targetLangSignature(bool minimal) const
|
|
727 {
|
|
728 QString s;
|
|
729
|
|
730 // Attributes...
|
|
731 if (!minimal) {
|
|
732 if (isPublic()) s += "public ";
|
|
733 else if (isProtected()) s += "protected ";
|
|
734 else if (isPrivate()) s += "private ";
|
|
735
|
|
736 // if (isNative()) s += "native ";
|
|
737 // else
|
|
738 if (isFinalInTargetLang()) s += "final ";
|
|
739 else if (isAbstract()) s += "abstract ";
|
|
740
|
|
741 if (isStatic()) s += "static ";
|
|
742
|
|
743 // Return type
|
|
744 if (type())
|
|
745 s += type()->fullName() + " ";
|
|
746 else
|
|
747 s += "void ";
|
|
748 }
|
|
749
|
|
750 s += name();
|
|
751 s += "(";
|
|
752
|
|
753 for (int i=0; i<m_arguments.size(); ++i) {
|
|
754 if (i != 0) {
|
|
755 s += ",";
|
|
756 if (!minimal)
|
|
757 s += QLatin1Char(' ');
|
|
758 }
|
|
759 s += m_arguments.at(i)->type()->fullName();
|
|
760
|
|
761 if (!minimal) {
|
|
762 s += " ";
|
|
763 s += m_arguments.at(i)->argumentName();
|
|
764 }
|
|
765 }
|
|
766
|
|
767 s += ")";
|
|
768
|
|
769 return s;
|
|
770 }
|
|
771
|
|
772
|
|
773 bool function_sorter(AbstractMetaFunction *a, AbstractMetaFunction *b)
|
|
774 {
|
|
775 return a->signature() < b->signature();
|
|
776 }
|
|
777
|
|
778 /*******************************************************************************
|
|
779 * AbstractMetaClass
|
|
780 */
|
|
781 AbstractMetaClass::~AbstractMetaClass()
|
|
782 {
|
|
783 qDeleteAll(m_functions);
|
|
784 qDeleteAll(m_fields);
|
|
785 }
|
|
786
|
|
787 /*AbstractMetaClass *AbstractMetaClass::copy() const
|
|
788 {
|
|
789 AbstractMetaClass *cls = new AbstractMetaClass;
|
|
790 cls->setAttributes(attributes());
|
|
791 cls->setBaseClass(baseClass());
|
|
792 cls->setTypeEntry(typeEntry());
|
|
793 foreach (AbstractMetaFunction *function, functions()) {
|
|
794 AbstractMetaFunction *copy = function->copy();
|
|
795 function->setImplementingClass(cls);
|
|
796 cls->addFunction(copy);
|
|
797 }
|
|
798 cls->setEnums(enums());
|
|
799 foreach (const AbstractMetaField *field, fields()) {
|
|
800 AbstractMetaField *copy = field->copy();
|
|
801 copy->setEnclosingClass(cls);
|
|
802 cls->addField(copy);
|
|
803 }
|
|
804 cls->setInterfaces(interfaces());
|
|
805
|
|
806 return cls;
|
|
807 }*/
|
|
808
|
|
809 /*******************************************************************************
|
|
810 * Returns true if this class is a subclass of the given class
|
|
811 */
|
|
812 bool AbstractMetaClass::inheritsFrom(const AbstractMetaClass *cls) const
|
|
813 {
|
|
814 Q_ASSERT(cls != 0);
|
|
815
|
|
816 const AbstractMetaClass *clazz = this;
|
|
817 while (clazz != 0) {
|
|
818 if (clazz == cls)
|
|
819 return true;
|
|
820
|
|
821 clazz = clazz->baseClass();
|
|
822 }
|
|
823
|
|
824 return false;
|
|
825 }
|
|
826
|
|
827 /*******************************************************************************
|
|
828 * Constructs an interface based on the functions and enums in this
|
|
829 * class and returns it...
|
|
830 */
|
|
831 AbstractMetaClass *AbstractMetaClass::extractInterface()
|
|
832 {
|
|
833 Q_ASSERT(typeEntry()->designatedInterface());
|
|
834
|
|
835 if (m_extracted_interface == 0) {
|
|
836 AbstractMetaClass *iface = new AbstractMetaClass;
|
|
837 iface->setAttributes(attributes());
|
|
838 iface->setBaseClass(0);
|
|
839 iface->setPrimaryInterfaceImplementor(this);
|
|
840
|
|
841 iface->setTypeEntry(typeEntry()->designatedInterface());
|
|
842
|
|
843 foreach (AbstractMetaFunction *function, functions()) {
|
|
844 if (!function->isConstructor())
|
|
845 iface->addFunction(function->copy());
|
|
846 }
|
|
847
|
|
848 // iface->setEnums(enums());
|
|
849 // setEnums(AbstractMetaEnumList());
|
|
850
|
|
851 foreach (const AbstractMetaField *field, fields()) {
|
|
852 if (field->isPublic()) {
|
|
853 AbstractMetaField *new_field = field->copy();
|
|
854 new_field->setEnclosingClass(iface);
|
|
855 iface->addField(new_field);
|
|
856 }
|
|
857 }
|
|
858
|
|
859 m_extracted_interface = iface;
|
|
860 addInterface(iface);
|
|
861 }
|
|
862
|
|
863 return m_extracted_interface;
|
|
864 }
|
|
865
|
|
866 /*******************************************************************************
|
|
867 * Returns a list of all the functions with a given name
|
|
868 */
|
|
869 AbstractMetaFunctionList AbstractMetaClass::queryFunctionsByName(const QString &name) const
|
|
870 {
|
|
871 AbstractMetaFunctionList returned;
|
|
872 AbstractMetaFunctionList functions = this->functions();
|
|
873 foreach (AbstractMetaFunction *function, functions) {
|
|
874 if (function->name() == name)
|
|
875 returned.append(function);
|
|
876 }
|
|
877
|
|
878 return returned;
|
|
879 }
|
|
880
|
|
881 /*******************************************************************************
|
|
882 * Returns all reference count modifications for any function in the class
|
|
883 */
|
|
884 QList<ReferenceCount> AbstractMetaClass::referenceCounts() const
|
|
885 {
|
|
886 QList<ReferenceCount> returned;
|
|
887
|
|
888 AbstractMetaFunctionList functions = this->functions();
|
|
889 foreach (AbstractMetaFunction *function, functions) {
|
|
890 returned += function->referenceCounts(this);
|
|
891 }
|
|
892
|
|
893 return returned;
|
|
894 }
|
|
895
|
|
896 /*******************************************************************************
|
|
897 * Returns a list of all the functions retrieved during parsing which should
|
|
898 * be added to the Java API.
|
|
899 */
|
|
900 AbstractMetaFunctionList AbstractMetaClass::functionsInTargetLang() const
|
|
901 {
|
|
902 int default_flags = NormalFunctions | Visible | NotRemovedFromTargetLang;
|
|
903
|
|
904 // Interfaces don't implement functions
|
|
905 default_flags |= isInterface() ? 0 : ClassImplements;
|
|
906
|
|
907 // Only public functions in final classes
|
|
908 // default_flags |= isFinal() ? WasPublic : 0;
|
|
909 int public_flags = isFinal() ? WasPublic : 0;
|
|
910
|
|
911 // Constructors
|
|
912 AbstractMetaFunctionList returned = queryFunctions(Constructors | default_flags | public_flags);
|
|
913
|
|
914 // Final functions
|
|
915 returned += queryFunctions(FinalInTargetLangFunctions | NonStaticFunctions | default_flags | public_flags);
|
|
916
|
|
917 // Virtual functions
|
|
918 returned += queryFunctions(VirtualInTargetLangFunctions | NonStaticFunctions | default_flags | public_flags);
|
|
919
|
|
920 // Static functions
|
|
921 returned += queryFunctions(StaticFunctions | default_flags | public_flags);
|
|
922
|
|
923 // Empty, private functions, since they aren't caught by the other ones
|
|
924 returned += queryFunctions(Empty | Invisible);
|
|
925
|
|
926 return returned;
|
|
927 }
|
|
928
|
|
929 AbstractMetaFunctionList AbstractMetaClass::virtualFunctions() const
|
|
930 {
|
|
931 AbstractMetaFunctionList list = functionsInShellClass();
|
|
932
|
|
933 AbstractMetaFunctionList returned;
|
|
934 foreach (AbstractMetaFunction *f, list) {
|
|
935 if (!f->isFinalInCpp() || f->isVirtualSlot())
|
|
936 returned += f;
|
|
937 }
|
|
938
|
|
939 return returned;
|
|
940 }
|
|
941
|
|
942 AbstractMetaFunctionList AbstractMetaClass::nonVirtualShellFunctions() const
|
|
943 {
|
|
944 AbstractMetaFunctionList list = functionsInShellClass();
|
|
945 AbstractMetaFunctionList returned;
|
|
946 foreach (AbstractMetaFunction *f, list) {
|
|
947 if (f->isFinalInCpp() && !f->isVirtualSlot())
|
|
948 returned += f;
|
|
949 }
|
|
950
|
|
951 return returned;
|
|
952 }
|
|
953
|
|
954 /*******************************************************************************
|
|
955 * Returns a list of all functions that should be declared and implemented in
|
|
956 * the shell class which is generated as a wrapper on top of the actual C++ class
|
|
957 */
|
|
958 AbstractMetaFunctionList AbstractMetaClass::functionsInShellClass() const
|
|
959 {
|
|
960 // Only functions and only protected and public functions
|
|
961 int default_flags = NormalFunctions | Visible | WasVisible | NotRemovedFromShell;
|
|
962
|
|
963 // All virtual functions
|
|
964 AbstractMetaFunctionList returned = queryFunctions(VirtualFunctions | default_flags);
|
|
965
|
|
966 // All functions explicitly set to be implemented by the shell class
|
|
967 // (mainly superclass functions that are hidden by other declarations)
|
|
968 returned += queryFunctions(ForcedShellFunctions | default_flags);
|
|
969
|
|
970 // All functions explicitly set to be virtual slots
|
|
971 returned += queryFunctions(VirtualSlots | default_flags);
|
|
972
|
|
973 return returned;
|
|
974 }
|
|
975
|
|
976 /*******************************************************************************
|
|
977 * Returns a list of all functions that require a public override function to
|
|
978 * be generated in the shell class. This includes all functions that were originally
|
|
979 * protected in the superclass.
|
|
980 */
|
|
981 AbstractMetaFunctionList AbstractMetaClass::publicOverrideFunctions() const
|
|
982 {
|
|
983 return queryFunctions(NormalFunctions | WasProtected | FinalInCppFunctions | NotRemovedFromTargetLang)
|
|
984 + queryFunctions(Signals | WasProtected | FinalInCppFunctions | NotRemovedFromTargetLang);
|
|
985 }
|
|
986
|
|
987 AbstractMetaFunctionList AbstractMetaClass::virtualOverrideFunctions() const
|
|
988 {
|
|
989 return queryFunctions(NormalFunctions | NonEmptyFunctions | Visible | VirtualInCppFunctions | NotRemovedFromShell) +
|
|
990 queryFunctions(Signals | NonEmptyFunctions | Visible | VirtualInCppFunctions | NotRemovedFromShell);
|
|
991 }
|
|
992
|
|
993 void AbstractMetaClass::sortFunctions()
|
|
994 {
|
|
995 qSort(m_functions.begin(), m_functions.end(), function_sorter);
|
|
996 }
|
|
997
|
|
998 void AbstractMetaClass::setFunctions(const AbstractMetaFunctionList &functions)
|
|
999 {
|
|
1000 m_functions = functions;
|
|
1001
|
|
1002 // Functions must be sorted by name before next loop
|
|
1003 sortFunctions();
|
|
1004
|
|
1005 QString currentName;
|
|
1006 bool hasVirtuals = false;
|
|
1007 AbstractMetaFunctionList final_functions;
|
|
1008 foreach (AbstractMetaFunction *f, m_functions) {
|
|
1009 f->setOwnerClass(this);
|
|
1010
|
|
1011 m_has_virtual_slots |= f->isVirtualSlot();
|
|
1012 m_has_virtuals |= !f->isFinal() || f->isVirtualSlot();
|
|
1013 m_has_nonpublic |= !f->isPublic();
|
|
1014
|
|
1015 // If we have non-virtual overloads of a virtual function, we have to implement
|
|
1016 // all the overloads in the shell class to override the hiding rule
|
|
1017 if (currentName == f->name()) {
|
|
1018 hasVirtuals = hasVirtuals || !f->isFinal();
|
|
1019 if (f->isFinal())
|
|
1020 final_functions += f;
|
|
1021 } else {
|
|
1022 if (hasVirtuals && final_functions.size() > 0) {
|
|
1023 foreach (AbstractMetaFunction *final_function, final_functions) {
|
|
1024 *final_function += AbstractMetaAttributes::ForceShellImplementation;
|
|
1025
|
|
1026 QString warn = QString("hiding of function '%1' in class '%2'")
|
|
1027 .arg(final_function->name()).arg(name());
|
|
1028 ReportHandler::warning(warn);
|
|
1029 }
|
|
1030 }
|
|
1031
|
|
1032 hasVirtuals = !f->isFinal();
|
|
1033 final_functions.clear();
|
|
1034 if (f->isFinal())
|
|
1035 final_functions += f;
|
|
1036 currentName = f->name();
|
|
1037 }
|
|
1038 }
|
|
1039
|
|
1040 #ifndef QT_NO_DEBUG
|
|
1041 bool duplicate_function = false;
|
|
1042 for (int j=0; j<m_functions.size(); ++j) {
|
|
1043 FunctionModificationList mods = m_functions.at(j)->modifications(m_functions.at(j)->implementingClass());
|
|
1044
|
|
1045 bool removed = false;
|
|
1046 foreach (const FunctionModification &mod, mods) {
|
|
1047 if (mod.isRemoveModifier()) {
|
|
1048 removed = true;
|
|
1049 break ;
|
|
1050 }
|
|
1051 }
|
|
1052 if (removed)
|
|
1053 continue ;
|
|
1054
|
|
1055 for (int i=0; i<m_functions.size() - 1; ++i) {
|
|
1056 if (j == i)
|
|
1057 continue;
|
|
1058
|
|
1059 mods = m_functions.at(i)->modifications(m_functions.at(i)->implementingClass());
|
|
1060 bool removed = false;
|
|
1061 foreach (const FunctionModification &mod, mods) {
|
|
1062 if (mod.isRemoveModifier()) {
|
|
1063 removed = true;
|
|
1064 break ;
|
|
1065 }
|
|
1066 }
|
|
1067 if (removed)
|
|
1068 continue ;
|
|
1069
|
|
1070 uint cmp = m_functions.at(i)->compareTo(m_functions.at(j));
|
|
1071 if ((cmp & AbstractMetaFunction::EqualName) && (cmp & AbstractMetaFunction::EqualArguments)) {
|
|
1072 printf("%s.%s mostly equal to %s.%s\n",
|
|
1073 qPrintable(m_functions.at(i)->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1074 qPrintable(m_functions.at(i)->signature()),
|
|
1075 qPrintable(m_functions.at(j)->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1076 qPrintable(m_functions.at(j)->signature()));
|
|
1077 duplicate_function = true;
|
|
1078 }
|
|
1079 }
|
|
1080 }
|
|
1081 //Q_ASSERT(!duplicate_function);
|
|
1082 #endif
|
|
1083 }
|
|
1084
|
|
1085 bool AbstractMetaClass::hasFieldAccessors() const
|
|
1086 {
|
|
1087 foreach (const AbstractMetaField *field, fields()) {
|
|
1088 if (field->getter() || field->setter())
|
|
1089 return true;
|
|
1090 }
|
|
1091
|
|
1092 return false;
|
|
1093 }
|
|
1094
|
|
1095 bool AbstractMetaClass::hasDefaultToStringFunction() const
|
|
1096 {
|
|
1097 foreach (AbstractMetaFunction *f, queryFunctionsByName("toString")) {
|
|
1098 if (f->actualMinimumArgumentCount() == 0) {
|
|
1099 return true;
|
|
1100 }
|
|
1101
|
|
1102 }
|
|
1103 return false;
|
|
1104 }
|
|
1105
|
|
1106 void AbstractMetaClass::addFunction(AbstractMetaFunction *function)
|
|
1107 {
|
|
1108 function->setOwnerClass(this);
|
|
1109
|
|
1110 if (!function->isDestructor()) {
|
|
1111 m_functions << function;
|
|
1112 qSort(m_functions.begin(), m_functions.end(), function_sorter);
|
|
1113 }
|
260
|
1114
|
1
|
1115 m_has_virtual_slots |= function->isVirtualSlot();
|
|
1116 m_has_virtuals |= !function->isFinal() || function->isVirtualSlot();
|
|
1117 m_has_nonpublic |= !function->isPublic();
|
|
1118 }
|
|
1119
|
|
1120 bool AbstractMetaClass::hasSignal(const AbstractMetaFunction *other) const
|
|
1121 {
|
|
1122 if (!other->isSignal())
|
|
1123 return false;
|
|
1124
|
|
1125 foreach (const AbstractMetaFunction *f, functions()) {
|
|
1126 if (f->isSignal() && f->compareTo(other) & AbstractMetaFunction::EqualName)
|
|
1127 return other->modifiedName() == f->modifiedName();
|
|
1128 }
|
|
1129
|
|
1130 return false;
|
|
1131 }
|
|
1132
|
|
1133
|
|
1134 QString AbstractMetaClass::name() const
|
|
1135 {
|
|
1136 return QString(m_type_entry->targetLangName()).replace("::", "_");
|
|
1137 }
|
|
1138
|
|
1139 bool AbstractMetaClass::hasFunction(const QString &str) const
|
|
1140 {
|
|
1141 foreach (const AbstractMetaFunction *f, functions())
|
|
1142 if (f->name() == str)
|
|
1143 return true;
|
|
1144 return false;
|
|
1145 }
|
|
1146
|
|
1147 /* Returns true if this class has one or more functions that are
|
|
1148 protected. If a class has protected members we need to generate a
|
|
1149 shell class with public accessors to the protected functions, so
|
|
1150 they can be called from the native functions.
|
|
1151 */
|
|
1152 bool AbstractMetaClass::hasProtectedFunctions() const {
|
|
1153 foreach (AbstractMetaFunction *func, m_functions) {
|
|
1154 if (func->isProtected())
|
|
1155 return true;
|
|
1156 }
|
|
1157 return false;
|
|
1158 }
|
|
1159
|
|
1160 bool AbstractMetaClass::generateShellClass() const
|
|
1161 {
|
310
|
1162 return m_force_shell_class ||
|
|
1163 ( /*!isFinal()
|
|
1164 && ( */
|
|
1165 isPolymorphic()
|
257
|
1166 || hasProtectedFunctions()
|
|
1167 || hasFieldAccessors()
|
310
|
1168 //|| typeEntry()->isObject() // qtd2 for being more consistent
|
|
1169 /*)*/
|
|
1170 );
|
1
|
1171 }
|
|
1172
|
|
1173 QPropertySpec *AbstractMetaClass::propertySpecForRead(const QString &name) const
|
|
1174 {
|
|
1175 for (int i=0; i<m_property_specs.size(); ++i)
|
|
1176 if (name == m_property_specs.at(i)->read())
|
|
1177 return m_property_specs.at(i);
|
|
1178 return 0;
|
|
1179 }
|
|
1180
|
|
1181 QPropertySpec *AbstractMetaClass::propertySpecForWrite(const QString &name) const
|
|
1182 {
|
|
1183 for (int i=0; i<m_property_specs.size(); ++i)
|
|
1184 if (name == m_property_specs.at(i)->write())
|
|
1185 return m_property_specs.at(i);
|
|
1186 return 0;
|
|
1187 }
|
|
1188
|
|
1189 QPropertySpec *AbstractMetaClass::propertySpecForReset(const QString &name) const
|
|
1190 {
|
|
1191 for (int i=0; i<m_property_specs.size(); ++i) {
|
|
1192 if (name == m_property_specs.at(i)->reset())
|
|
1193 return m_property_specs.at(i);
|
|
1194 }
|
|
1195 return 0;
|
|
1196 }
|
|
1197
|
|
1198
|
|
1199
|
|
1200 static bool functions_contains(const AbstractMetaFunctionList &l, const AbstractMetaFunction *func)
|
|
1201 {
|
|
1202 foreach (const AbstractMetaFunction *f, l) {
|
|
1203 if ((f->compareTo(func) & AbstractMetaFunction::PrettySimilar) == AbstractMetaFunction::PrettySimilar)
|
|
1204 return true;
|
|
1205 }
|
|
1206 return false;
|
|
1207 }
|
|
1208
|
|
1209 AbstractMetaField::AbstractMetaField() : m_getter(0), m_setter(0), m_class(0)
|
|
1210 {
|
|
1211 }
|
|
1212
|
|
1213 AbstractMetaField::~AbstractMetaField()
|
|
1214 {
|
|
1215 delete m_setter;
|
|
1216 delete m_getter;
|
|
1217 }
|
|
1218 ushort painters; // refcount
|
|
1219 AbstractMetaField *AbstractMetaField::copy() const
|
|
1220 {
|
|
1221 AbstractMetaField *returned = new AbstractMetaField;
|
|
1222 returned->setEnclosingClass(0);
|
|
1223 returned->setAttributes(attributes());
|
|
1224 returned->setName(name());
|
|
1225 returned->setType(type()->copy());
|
|
1226 returned->setOriginalAttributes(originalAttributes());
|
|
1227
|
|
1228 return returned;
|
|
1229 }
|
|
1230
|
|
1231 static QString upCaseFirst(const QString &str) {
|
|
1232 Q_ASSERT(!str.isEmpty());
|
|
1233 QString s = str;
|
|
1234 s[0] = s.at(0).toUpper();
|
|
1235 return s;
|
|
1236 }
|
|
1237
|
|
1238 static AbstractMetaFunction *createXetter(const AbstractMetaField *g, const QString &name, uint type) {
|
|
1239 AbstractMetaFunction *f = new AbstractMetaFunction;
|
|
1240
|
|
1241
|
|
1242
|
|
1243 f->setName(name);
|
|
1244 f->setOriginalName(name);
|
|
1245 f->setOwnerClass(g->enclosingClass());
|
|
1246 f->setImplementingClass(g->enclosingClass());
|
|
1247 f->setDeclaringClass(g->enclosingClass());
|
|
1248
|
|
1249 uint attr = AbstractMetaAttributes::Native
|
|
1250 | AbstractMetaAttributes::Final
|
|
1251 | type;
|
|
1252 if (g->isStatic())
|
|
1253 attr |= AbstractMetaAttributes::Static;
|
|
1254 if (g->isPublic())
|
|
1255 attr |= AbstractMetaAttributes::Public;
|
|
1256 else if (g->isProtected())
|
|
1257 attr |= AbstractMetaAttributes::Protected;
|
|
1258 else
|
|
1259 attr |= AbstractMetaAttributes::Private;
|
|
1260 f->setAttributes(attr);
|
|
1261 f->setOriginalAttributes(attr);
|
|
1262
|
|
1263 FieldModificationList mods = g->modifications();
|
|
1264 foreach (FieldModification mod, mods) {
|
|
1265 if (mod.isRenameModifier())
|
|
1266 f->setName(mod.renamedTo());
|
|
1267 if (mod.isAccessModifier()) {
|
|
1268 if (mod.isPrivate())
|
|
1269 f->setVisibility(AbstractMetaAttributes::Private);
|
|
1270 else if (mod.isProtected())
|
|
1271 f->setVisibility(AbstractMetaAttributes::Protected);
|
|
1272 else if (mod.isPublic())
|
|
1273 f->setVisibility(AbstractMetaAttributes::Public);
|
|
1274 else if (mod.isFriendly())
|
|
1275 f->setVisibility(AbstractMetaAttributes::Friendly);
|
|
1276 }
|
|
1277
|
|
1278 }
|
|
1279 return f;
|
|
1280 }
|
|
1281
|
|
1282 FieldModificationList AbstractMetaField::modifications() const
|
|
1283 {
|
|
1284 FieldModificationList mods = enclosingClass()->typeEntry()->fieldModifications();
|
|
1285 FieldModificationList returned;
|
|
1286
|
|
1287 foreach (FieldModification mod, mods) {
|
|
1288 if (mod.name == name())
|
|
1289 returned += mod;
|
|
1290 }
|
|
1291
|
|
1292 return returned;
|
|
1293 }
|
|
1294
|
|
1295 const AbstractMetaFunction *AbstractMetaField::setter() const
|
|
1296 {
|
|
1297 if (m_setter == 0) {
|
|
1298 m_setter = createXetter(this,
|
|
1299 "set" + upCaseFirst(name()),
|
|
1300 AbstractMetaAttributes::SetterFunction);
|
|
1301 AbstractMetaArgumentList arguments;
|
|
1302 AbstractMetaArgument *argument = new AbstractMetaArgument;
|
|
1303 argument->setType(type()->copy());
|
|
1304 argument->setName(name());
|
|
1305 arguments.append(argument);
|
|
1306 m_setter->setArguments(arguments);
|
|
1307 }
|
|
1308 return m_setter;
|
|
1309 }
|
|
1310
|
|
1311 const AbstractMetaFunction *AbstractMetaField::getter() const
|
|
1312 {
|
|
1313 if (m_getter == 0) {
|
|
1314 m_getter = createXetter(this,
|
|
1315 name(),
|
|
1316 AbstractMetaAttributes::GetterFunction);
|
|
1317 m_getter->setType(type());
|
|
1318 }
|
|
1319
|
|
1320 return m_getter;
|
|
1321 }
|
|
1322
|
|
1323
|
|
1324 bool AbstractMetaClass::hasConstructors() const
|
|
1325 {
|
|
1326 return queryFunctions(Constructors).size() != 0;
|
|
1327 }
|
|
1328
|
|
1329 void AbstractMetaClass::addDefaultConstructor()
|
|
1330 {
|
|
1331 AbstractMetaFunction *f = new AbstractMetaFunction;
|
|
1332 f->setName(name());
|
|
1333 f->setOwnerClass(this);
|
|
1334 f->setFunctionType(AbstractMetaFunction::ConstructorFunction);
|
|
1335 f->setArguments(AbstractMetaArgumentList());
|
|
1336 f->setDeclaringClass(this);
|
|
1337
|
|
1338 uint attr = AbstractMetaAttributes::Native;
|
|
1339 attr |= AbstractMetaAttributes::Public;
|
|
1340 attr |= AbstractMetaAttributes::Final; // qtd otherwise added constructor is virtual which in fact it is not
|
|
1341 f->setAttributes(attr);
|
|
1342 f->setImplementingClass(this);
|
|
1343 f->setOriginalAttributes(f->attributes());
|
|
1344
|
310
|
1345 addFunction(f);
|
1
|
1346 }
|
|
1347
|
|
1348 bool AbstractMetaClass::hasFunction(const AbstractMetaFunction *f) const
|
|
1349 {
|
|
1350 return functions_contains(m_functions, f);
|
|
1351 }
|
|
1352
|
|
1353 /* Goes through the list of functions and returns a list of all
|
|
1354 functions matching all of the criteria in \a query.
|
|
1355 */
|
|
1356
|
|
1357 AbstractMetaFunctionList AbstractMetaClass::queryFunctions(uint query) const
|
|
1358 {
|
|
1359 AbstractMetaFunctionList functions;
|
|
1360
|
|
1361 foreach (AbstractMetaFunction *f, m_functions) {
|
|
1362
|
|
1363 if ((query & VirtualSlots) && !f->isVirtualSlot())
|
|
1364 continue;
|
|
1365
|
|
1366 if ((query & NotRemovedFromTargetLang) && f->isRemovedFrom(f->implementingClass(), TypeSystem::TargetLangCode)) {
|
|
1367 continue;
|
|
1368 }
|
|
1369
|
|
1370 if ((query & NotRemovedFromTargetLang) && !f->isFinal() && f->isRemovedFrom(f->declaringClass(), TypeSystem::TargetLangCode)) {
|
|
1371 continue;
|
|
1372 }
|
|
1373
|
|
1374 if ((query & NotRemovedFromShell) && f->isRemovedFrom(f->implementingClass(), TypeSystem::ShellCode)) {
|
|
1375 continue;
|
|
1376 }
|
|
1377
|
|
1378 if ((query & NotRemovedFromShell) && !f->isFinal() && f->isRemovedFrom(f->declaringClass(), TypeSystem::ShellCode)) {
|
|
1379 continue;
|
|
1380 }
|
|
1381
|
|
1382 if ((query & Visible) && f->isPrivate()) {
|
|
1383 continue;
|
|
1384 }
|
|
1385
|
|
1386 if ((query & VirtualInTargetLangFunctions) && f->isFinalInTargetLang()) {
|
|
1387 continue;
|
|
1388 }
|
|
1389
|
|
1390 if ((query & Invisible) && !f->isPrivate()) {
|
|
1391 continue;
|
|
1392 }
|
|
1393
|
|
1394 if ((query & Empty) && !f->isEmptyFunction()) {
|
|
1395 continue;
|
|
1396 }
|
|
1397
|
|
1398 if ((query & WasPublic) && !f->wasPublic()) {
|
|
1399 continue;
|
|
1400 }
|
|
1401
|
|
1402 if ((query & WasVisible) && f->wasPrivate()) {
|
|
1403 continue;
|
|
1404 }
|
|
1405
|
|
1406 if ((query & WasProtected) && !f->wasProtected()) {
|
|
1407 continue;
|
|
1408 }
|
|
1409
|
|
1410 if ((query & ClassImplements) && f->ownerClass() != f->implementingClass()) {
|
|
1411 continue;
|
|
1412 }
|
|
1413
|
|
1414 if ((query & Inconsistent) && (f->isFinalInTargetLang() || !f->isFinalInCpp() || f->isStatic())) {
|
|
1415 continue;
|
|
1416 }
|
|
1417
|
|
1418 if ((query & FinalInTargetLangFunctions) && !f->isFinalInTargetLang()) {
|
|
1419 continue;
|
|
1420 }
|
|
1421
|
|
1422 if ((query & FinalInCppFunctions) && !f->isFinalInCpp()) {
|
|
1423 continue;
|
|
1424 }
|
|
1425
|
|
1426 if ((query & VirtualInCppFunctions) && f->isFinalInCpp()) {
|
|
1427 continue;
|
|
1428 }
|
|
1429
|
|
1430 if ((query & Signals) && (!f->isSignal())) {
|
|
1431 continue;
|
|
1432 }
|
|
1433
|
|
1434 if ((query & ForcedShellFunctions)
|
|
1435 && (!f->isForcedShellImplementation()
|
|
1436 || !f->isFinal())) {
|
|
1437 continue;
|
|
1438 }
|
|
1439
|
|
1440 if ((query & Constructors) && (!f->isConstructor()
|
|
1441 || f->ownerClass() != f->implementingClass())
|
|
1442 || f->isConstructor() && (query & Constructors) == 0) {
|
|
1443 continue;
|
|
1444 }
|
|
1445
|
|
1446 // Destructors are never included in the functions of a class currently
|
|
1447 /*
|
|
1448 if ((query & Destructors) && (!f->isDestructor()
|
|
1449 || f->ownerClass() != f->implementingClass())
|
|
1450 || f->isDestructor() && (query & Destructors) == 0) {
|
|
1451 continue;
|
|
1452 }*/
|
|
1453
|
|
1454 if ((query & VirtualFunctions) && (f->isFinal() || f->isSignal() || f->isStatic())) {
|
|
1455 continue;
|
|
1456 }
|
|
1457
|
|
1458 if ((query & StaticFunctions) && (!f->isStatic() || f->isSignal())) {
|
|
1459 continue;
|
|
1460 }
|
|
1461
|
|
1462 if ((query & NonStaticFunctions) && (f->isStatic())) {
|
|
1463 continue;
|
|
1464 }
|
|
1465
|
|
1466 if ((query & NonEmptyFunctions) && (f->isEmptyFunction())) {
|
|
1467 continue;
|
|
1468 }
|
|
1469
|
|
1470 if ((query & NormalFunctions) && (f->isSignal())) {
|
|
1471 continue;
|
|
1472 }
|
|
1473
|
|
1474 if ((query & AbstractFunctions) && !f->isAbstract()) {
|
|
1475 continue;
|
|
1476 }
|
|
1477
|
|
1478 functions << f;
|
|
1479 }
|
|
1480
|
|
1481 // qDebug() << "queried" << m_type_entry->qualifiedCppName() << "got" << functions.size() << "out of" << m_functions.size();
|
|
1482
|
|
1483 return functions;
|
|
1484 }
|
|
1485
|
|
1486
|
|
1487 bool AbstractMetaClass::hasInconsistentFunctions() const
|
|
1488 {
|
|
1489 return cppInconsistentFunctions().size() > 0;
|
|
1490 }
|
|
1491
|
|
1492 bool AbstractMetaClass::hasSignals() const
|
|
1493 {
|
|
1494 return cppSignalFunctions().size() > 0;
|
|
1495 }
|
|
1496
|
|
1497
|
|
1498 /**
|
|
1499 * Adds the specified interface to this class by adding all the
|
|
1500 * functions in the interface to this class.
|
|
1501 */
|
|
1502 void AbstractMetaClass::addInterface(AbstractMetaClass *interface)
|
|
1503 {
|
|
1504 Q_ASSERT(!m_interfaces.contains(interface));
|
|
1505 m_interfaces << interface;
|
|
1506
|
|
1507 if (m_extracted_interface != 0 && m_extracted_interface != interface)
|
|
1508 m_extracted_interface->addInterface(interface);
|
|
1509
|
|
1510 foreach (AbstractMetaFunction *function, interface->functions())
|
|
1511 if (!hasFunction(function) && !function->isConstructor()) {
|
|
1512 AbstractMetaFunction *cpy = function->copy();
|
|
1513 cpy->setImplementingClass(this);
|
|
1514
|
|
1515 // Setup that this function is an interface class.
|
|
1516 cpy->setInterfaceClass(interface);
|
|
1517 *cpy += AbstractMetaAttributes::InterfaceFunction;
|
|
1518
|
|
1519 // Copy the modifications in interface into the implementing classes.
|
|
1520 FunctionModificationList mods = function->modifications(interface);
|
|
1521 foreach (const FunctionModification &mod, mods) {
|
|
1522 m_type_entry->addFunctionModification(mod);
|
|
1523 }
|
|
1524
|
|
1525 // It should be mostly safe to assume that when we implement an interface
|
|
1526 // we don't "pass on" pure virtual functions to our sublcasses...
|
|
1527 // *cpy -= AbstractMetaAttributes::Abstract;
|
|
1528
|
|
1529 addFunction(cpy);
|
|
1530 }
|
|
1531 }
|
|
1532
|
|
1533
|
|
1534 void AbstractMetaClass::setInterfaces(const AbstractMetaClassList &interfaces)
|
|
1535 {
|
|
1536 m_interfaces = interfaces;
|
|
1537 }
|
|
1538
|
|
1539
|
|
1540 AbstractMetaEnum *AbstractMetaClass::findEnum(const QString &enumName)
|
|
1541 {
|
|
1542 foreach (AbstractMetaEnum *e, m_enums) {
|
|
1543 if (e->name() == enumName)
|
|
1544 return e;
|
|
1545 }
|
|
1546
|
|
1547 if (typeEntry()->designatedInterface())
|
|
1548 return extractInterface()->findEnum(enumName);
|
|
1549
|
|
1550 return 0;
|
|
1551 }
|
|
1552
|
|
1553
|
|
1554
|
|
1555
|
|
1556 /*! Recursivly searches for the enum value named \a enumValueName in
|
|
1557 this class and its superclasses and interfaces. Values belonging to
|
|
1558 \a meta_enum are excluded from the search.
|
|
1559 */
|
|
1560 AbstractMetaEnumValue *AbstractMetaClass::findEnumValue(const QString &enumValueName, AbstractMetaEnum *meta_enum)
|
|
1561 {
|
|
1562 foreach (AbstractMetaEnum *e, m_enums) {
|
|
1563 if (e == meta_enum)
|
|
1564 continue;
|
|
1565 foreach (AbstractMetaEnumValue *v, e->values()) {
|
|
1566 if (v->name() == enumValueName)
|
|
1567 return v;
|
|
1568 }
|
|
1569 }
|
|
1570
|
|
1571 if (typeEntry()->designatedInterface())
|
|
1572 return extractInterface()->findEnumValue(enumValueName, meta_enum);
|
|
1573
|
|
1574 if (baseClass() != 0)
|
|
1575 return baseClass()->findEnumValue(enumValueName, meta_enum);
|
|
1576
|
|
1577 return 0;
|
|
1578 }
|
|
1579
|
|
1580
|
|
1581 /*!
|
|
1582 * Searches through all of this class' enums for a value matching the
|
|
1583 * name \a enumValueName. The name is excluding the class/namespace
|
|
1584 * prefix. The function recursivly searches interfaces and baseclasses
|
|
1585 * of this class.
|
|
1586 */
|
|
1587 AbstractMetaEnum *AbstractMetaClass::findEnumForValue(const QString &enumValueName)
|
|
1588 {
|
|
1589 foreach (AbstractMetaEnum *e, m_enums) {
|
|
1590 foreach (AbstractMetaEnumValue *v, e->values()) {
|
|
1591 if (v->name() == enumValueName)
|
|
1592 return e;
|
|
1593 }
|
|
1594 }
|
|
1595
|
|
1596 if (typeEntry()->designatedInterface())
|
|
1597 return extractInterface()->findEnumForValue(enumValueName);
|
|
1598
|
|
1599 if (baseClass() != 0)
|
|
1600 return baseClass()->findEnumForValue(enumValueName);
|
|
1601
|
|
1602 return 0;
|
|
1603 }
|
|
1604
|
|
1605
|
|
1606 static void add_extra_include_for_type(AbstractMetaClass *meta_class, const AbstractMetaType *type)
|
|
1607 {
|
|
1608
|
|
1609 if (type == 0)
|
|
1610 return;
|
|
1611
|
|
1612 Q_ASSERT(meta_class != 0);
|
|
1613 const TypeEntry *entry = (type ? type->typeEntry() : 0);
|
|
1614 if (entry != 0 && entry->isComplex()) {
|
|
1615 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(entry);
|
|
1616 ComplexTypeEntry *class_entry = meta_class->typeEntry();
|
|
1617 if (class_entry != 0 && centry->include().isValid())
|
|
1618 class_entry->addExtraInclude(centry->include());
|
|
1619 }
|
|
1620
|
|
1621 if (type->hasInstantiations()) {
|
|
1622 QList<AbstractMetaType *> instantiations = type->instantiations();
|
|
1623 foreach (AbstractMetaType *instantiation, instantiations)
|
|
1624 add_extra_include_for_type(meta_class, instantiation);
|
|
1625 }
|
|
1626 }
|
|
1627
|
|
1628 static void add_extra_includes_for_function(AbstractMetaClass *meta_class, const AbstractMetaFunction *meta_function)
|
|
1629 {
|
|
1630 Q_ASSERT(meta_class != 0);
|
|
1631 Q_ASSERT(meta_function != 0);
|
|
1632 add_extra_include_for_type(meta_class, meta_function->type());
|
|
1633
|
|
1634 AbstractMetaArgumentList arguments = meta_function->arguments();
|
|
1635 foreach (AbstractMetaArgument *argument, arguments)
|
|
1636 add_extra_include_for_type(meta_class, argument->type());
|
|
1637 }
|
|
1638
|
|
1639 void AbstractMetaClass::fixFunctions()
|
|
1640 {
|
|
1641 if (m_functions_fixed)
|
|
1642 return;
|
|
1643 else
|
|
1644 m_functions_fixed = true;
|
|
1645
|
|
1646 AbstractMetaClass *super_class = baseClass();
|
|
1647 AbstractMetaFunctionList funcs = functions();
|
|
1648
|
|
1649 // printf("fix functions for %s\n", qPrintable(name()));
|
|
1650
|
|
1651 if (super_class != 0)
|
|
1652 super_class->fixFunctions();
|
|
1653 int iface_idx = 0;
|
|
1654 while (super_class || iface_idx < interfaces().size()) {
|
|
1655 // printf(" - base: %s\n", qPrintable(super_class->name()));
|
|
1656
|
|
1657 // Since we always traverse the complete hierarchy we are only
|
|
1658 // interrested in what each super class implements, not what
|
|
1659 // we may have propagated from their base classes again.
|
|
1660 AbstractMetaFunctionList super_funcs;
|
|
1661 if (super_class) {
|
|
1662
|
|
1663 // Super classes can never be final
|
|
1664 if (super_class->isFinalInTargetLang()) {
|
|
1665 ReportHandler::warning("Final class '" + super_class->name() + "' set to non-final, as it is extended by other classes");
|
|
1666 *super_class -= AbstractMetaAttributes::FinalInTargetLang;
|
|
1667 }
|
|
1668 super_funcs = super_class->queryFunctions(AbstractMetaClass::ClassImplements);
|
|
1669 } else {
|
|
1670 super_funcs = interfaces().at(iface_idx)->queryFunctions(AbstractMetaClass::NormalFunctions);
|
|
1671 }
|
|
1672
|
|
1673 QSet<AbstractMetaFunction *> funcs_to_add;
|
|
1674 for (int sfi=0; sfi<super_funcs.size(); ++sfi) {
|
|
1675 AbstractMetaFunction *sf = super_funcs.at(sfi);
|
|
1676
|
|
1677 if (sf->isRemovedFromAllLanguages(sf->implementingClass()))
|
|
1678 continue;
|
|
1679
|
|
1680 // we generally don't care about private functions, but we have to get the ones that are
|
|
1681 // virtual in case they override abstract functions.
|
|
1682 bool add = (sf->isNormal() || sf->isSignal() || sf->isEmptyFunction());
|
|
1683 for (int fi=0; fi<funcs.size(); ++fi) {
|
|
1684 AbstractMetaFunction *f = funcs.at(fi);
|
|
1685 if (f->isRemovedFromAllLanguages(f->implementingClass()))
|
|
1686 continue;
|
|
1687
|
|
1688 uint cmp = f->compareTo(sf);
|
|
1689
|
|
1690 if (cmp & AbstractMetaFunction::EqualModifiedName) {
|
|
1691 // printf(" - %s::%s similar to %s::%s %x vs %x\n",
|
|
1692 // qPrintable(sf->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1693 // qPrintable(sf->name()),
|
|
1694 // qPrintable(f->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1695 // qPrintable(f->name()),
|
|
1696 // sf->attributes(),
|
|
1697 // f->attributes());
|
|
1698
|
|
1699 add = false;
|
|
1700 if (cmp & AbstractMetaFunction::EqualArguments) {
|
|
1701
|
|
1702 // if (!(cmp & AbstractMetaFunction::EqualReturnType)) {
|
|
1703 // ReportHandler::warning(QString("%1::%2 and %3::%4 differ in retur type")
|
|
1704 // .arg(sf->implementingClass()->name())
|
|
1705 // .arg(sf->name())
|
|
1706 // .arg(f->implementingClass()->name())
|
|
1707 // .arg(f->name()));
|
|
1708 // }
|
|
1709
|
|
1710 // Same function, propegate virtual...
|
|
1711 if (!(cmp & AbstractMetaFunction::EqualAttributes)) {
|
|
1712 if (!f->isEmptyFunction()) {
|
|
1713 if (!sf->isFinalInCpp() && f->isFinalInCpp()) {
|
|
1714 *f -= AbstractMetaAttributes::FinalInCpp;
|
|
1715 // printf(" --- inherit virtual\n");
|
|
1716 }
|
|
1717 if (!sf->isFinalInTargetLang() && f->isFinalInTargetLang()) {
|
|
1718 *f -= AbstractMetaAttributes::FinalInTargetLang;
|
|
1719 // printf(" --- inherit virtual\n");
|
|
1720 }
|
|
1721 if (!f->isFinalInTargetLang() && f->isPrivate()) {
|
|
1722 f->setFunctionType(AbstractMetaFunction::EmptyFunction);
|
|
1723 f->setVisibility(AbstractMetaAttributes::Protected);
|
|
1724 *f += AbstractMetaAttributes::FinalInTargetLang;
|
|
1725 ReportHandler::warning(QString("private virtual function '%1' in '%2'")
|
|
1726 .arg(f->signature())
|
|
1727 .arg(f->implementingClass()->name()));
|
|
1728 }
|
|
1729 }
|
|
1730 }
|
|
1731
|
|
1732 if (f->visibility() != sf->visibility()) {
|
|
1733 QString warn = QString("visibility of function '%1' modified in class '%2'")
|
|
1734 .arg(f->name()).arg(name());
|
|
1735 ReportHandler::warning(warn);
|
|
1736
|
|
1737 // If new visibility is private, we can't
|
|
1738 // do anything. If it isn't, then we
|
|
1739 // prefer the parent class's visibility
|
|
1740 // setting for the function.
|
|
1741 if (!f->isPrivate() && !sf->isPrivate())
|
|
1742 f->setVisibility(sf->visibility());
|
|
1743
|
|
1744 // Private overrides of abstract functions have to go into the class or
|
|
1745 // the subclasses will not compile as non-abstract classes.
|
|
1746 // But they don't need to be implemented, since they can never be called.
|
|
1747 if (f->isPrivate() && sf->isAbstract()) {
|
|
1748 f->setFunctionType(AbstractMetaFunction::EmptyFunction);
|
|
1749 f->setVisibility(sf->visibility());
|
|
1750 *f += AbstractMetaAttributes::FinalInTargetLang;
|
|
1751 *f += AbstractMetaAttributes::FinalInCpp;
|
|
1752 }
|
|
1753 }
|
|
1754
|
|
1755 // Set the class which first declares this function, afawk
|
|
1756 f->setDeclaringClass(sf->declaringClass());
|
|
1757
|
|
1758 if (sf->isFinalInTargetLang() && !sf->isPrivate() && !f->isPrivate() && !sf->isStatic() && !f->isStatic()) {
|
|
1759 // Shadowed funcion, need to make base class
|
|
1760 // function non-virtual
|
|
1761 if (f->implementingClass() != sf->implementingClass() && f->implementingClass()->inheritsFrom(sf->implementingClass())) {
|
|
1762
|
|
1763 // Check whether the superclass method has been redefined to non-final
|
|
1764
|
|
1765 bool hasNonFinalModifier = false;
|
|
1766 bool isBaseImplPrivate = false;
|
|
1767 FunctionModificationList mods = sf->modifications(sf->implementingClass());
|
|
1768 foreach (FunctionModification mod, mods) {
|
|
1769 if (mod.isNonFinal()) {
|
|
1770 hasNonFinalModifier = true;
|
|
1771 break;
|
|
1772 } else if (mod.isPrivate()) {
|
|
1773 isBaseImplPrivate = true;
|
|
1774 break;
|
|
1775 }
|
|
1776 }
|
|
1777
|
|
1778 if (!hasNonFinalModifier && !isBaseImplPrivate) {
|
|
1779 ReportHandler::warning(QString::fromLatin1("Shadowing: %1::%2 and %3::%4; Java code will not compile")
|
|
1780 .arg(sf->implementingClass()->name())
|
|
1781 .arg(sf->signature())
|
|
1782 .arg(f->implementingClass()->name())
|
|
1783 .arg(f->signature()));
|
|
1784 }
|
|
1785 }
|
|
1786 }
|
|
1787
|
|
1788 }
|
|
1789
|
|
1790 if (cmp & AbstractMetaFunction::EqualDefaultValueOverload) {
|
|
1791 AbstractMetaArgumentList arguments;
|
|
1792 if (f->arguments().size() < sf->arguments().size())
|
|
1793 arguments = sf->arguments();
|
|
1794 else
|
|
1795 arguments = f->arguments();
|
|
1796 /* qtd
|
|
1797 for (int i=0; i<arguments.size(); ++i)
|
|
1798 arguments[i]->setDefaultValueExpression(QString());
|
|
1799 */ }
|
|
1800
|
|
1801
|
|
1802 // Otherwise we have function shadowing and we can
|
|
1803 // skip the thing...
|
|
1804 } else if (cmp & AbstractMetaFunction::EqualName && !sf->isSignal()) {
|
|
1805
|
|
1806 // In the case of function shadowing where the function name has been altered to
|
|
1807 // avoid conflict, we don't copy in the original.
|
|
1808 add = false;
|
|
1809 }
|
|
1810
|
|
1811 }
|
|
1812
|
|
1813 if (add)
|
|
1814 funcs_to_add << sf;
|
|
1815 }
|
|
1816
|
|
1817 foreach (AbstractMetaFunction *f, funcs_to_add)
|
|
1818 funcs << f->copy();
|
|
1819
|
|
1820 if (super_class)
|
|
1821 super_class = super_class->baseClass();
|
|
1822 else
|
|
1823 iface_idx++;
|
|
1824 }
|
|
1825
|
|
1826 bool hasPrivateConstructors = false;
|
|
1827 bool hasPublicConstructors = false;
|
|
1828 foreach (AbstractMetaFunction *func, funcs) {
|
|
1829 FunctionModificationList mods = func->modifications(this);
|
|
1830 foreach (const FunctionModification &mod, mods) {
|
|
1831 if (mod.isRenameModifier()) {
|
|
1832 // qDebug() << name() << func->originalName() << func << " from "
|
|
1833 // << func->implementingClass()->name() << "renamed to" << mod.renamedTo();
|
|
1834 func->setName(mod.renamedTo());
|
|
1835 }
|
|
1836 }
|
|
1837
|
|
1838 // Make sure class is abstract if one of the functions is
|
|
1839 if (func->isAbstract()) {
|
|
1840 (*this) += AbstractMetaAttributes::Abstract;
|
|
1841 (*this) -= AbstractMetaAttributes::Final;
|
|
1842 }
|
|
1843
|
|
1844 if (func->isConstructor()) {
|
|
1845 if (func->isPrivate())
|
|
1846 hasPrivateConstructors = true;
|
|
1847 else
|
|
1848 hasPublicConstructors = true;
|
|
1849 }
|
|
1850
|
|
1851
|
|
1852
|
|
1853 // Make sure that we include files for all classes that are in use
|
|
1854
|
|
1855 if (!func->isRemovedFrom(this, TypeSystem::ShellCode))
|
|
1856 add_extra_includes_for_function(this, func);
|
|
1857 }
|
|
1858
|
|
1859 if (hasPrivateConstructors && !hasPublicConstructors) {
|
|
1860 (*this) += AbstractMetaAttributes::Abstract;
|
|
1861 (*this) -= AbstractMetaAttributes::Final;
|
|
1862 }
|
|
1863
|
|
1864 foreach (AbstractMetaFunction *f1, funcs) {
|
|
1865 foreach (AbstractMetaFunction *f2, funcs) {
|
|
1866 if (f1 != f2) {
|
|
1867 uint cmp = f1->compareTo(f2);
|
|
1868 if ((cmp & AbstractMetaFunction::EqualName)
|
|
1869 && !f1->isFinalInCpp()
|
|
1870 && f2->isFinalInCpp()) {
|
|
1871 *f2 += AbstractMetaAttributes::FinalOverload;
|
|
1872 // qDebug() << f2 << f2->implementingClass()->name() << "::" << f2->name() << f2->arguments().size() << " vs " << f1 << f1->implementingClass()->name() << "::" << f1->name() << f1->arguments().size();
|
|
1873 // qDebug() << " " << f2;
|
|
1874 // AbstractMetaArgumentList f2Args = f2->arguments();
|
|
1875 // foreach (AbstractMetaArgument *a, f2Args)
|
|
1876 // qDebug() << " " << a->type()->name() << a->name();
|
|
1877 // qDebug() << " " << f1;
|
|
1878 // AbstractMetaArgumentList f1Args = f1->arguments();
|
|
1879 // foreach (AbstractMetaArgument *a, f1Args)
|
|
1880 // qDebug() << " " << a->type()->name() << a->name();
|
|
1881
|
|
1882 }
|
|
1883 }
|
|
1884 }
|
|
1885 }
|
|
1886
|
|
1887 setFunctions(funcs);
|
|
1888 }
|
|
1889
|
|
1890
|
|
1891 QString AbstractMetaType::minimalSignature() const
|
|
1892 {
|
|
1893 QString minimalSignature;
|
|
1894 if (isConstant())
|
|
1895 minimalSignature += "const ";
|
|
1896 minimalSignature += typeEntry()->qualifiedCppName();
|
|
1897 if (hasInstantiations()) {
|
|
1898 QList<AbstractMetaType *> instantiations = this->instantiations();
|
|
1899 minimalSignature += "<";
|
|
1900 for (int i=0;i<instantiations.size();++i) {
|
|
1901 if (i > 0)
|
|
1902 minimalSignature += ",";
|
|
1903 minimalSignature += instantiations.at(i)->minimalSignature();
|
|
1904 }
|
|
1905 minimalSignature += ">";
|
|
1906 }
|
|
1907
|
|
1908 if (isReference())
|
|
1909 minimalSignature += "&";
|
|
1910 for (int j=0; j<indirections(); ++j)
|
|
1911 minimalSignature += "*";
|
|
1912
|
|
1913 return minimalSignature;
|
|
1914 }
|
|
1915
|
|
1916 bool AbstractMetaType::hasNativeId() const
|
|
1917 {
|
|
1918 return (isQObject() || isValue() || isObject()) && typeEntry()->isNativeIdBased();
|
|
1919 }
|
|
1920
|
|
1921
|
|
1922 /*******************************************************************************
|
|
1923 * Other stuff...
|
|
1924 */
|
|
1925
|
|
1926
|
|
1927 AbstractMetaEnum *AbstractMetaClassList::findEnum(const EnumTypeEntry *entry) const
|
|
1928 {
|
|
1929 Q_ASSERT(entry->isEnum());
|
|
1930
|
|
1931 QString qualified_name = entry->qualifiedCppName();
|
|
1932 int pos = qualified_name.lastIndexOf("::");
|
|
1933
|
|
1934 QString enum_name;
|
|
1935 QString class_name;
|
|
1936
|
|
1937 if (pos > 0) {
|
|
1938 enum_name = qualified_name.mid(pos + 2);
|
|
1939 class_name = qualified_name.mid(0, pos);
|
|
1940 } else {
|
|
1941 enum_name = qualified_name;
|
|
1942 class_name = TypeDatabase::globalNamespaceClassName(entry);
|
|
1943 }
|
|
1944
|
|
1945 AbstractMetaClass *meta_class = findClass(class_name);
|
|
1946 if (!meta_class) {
|
|
1947 ReportHandler::warning(QString("AbstractMeta::findEnum(), unknown class '%1' in '%2'")
|
|
1948 .arg(class_name).arg(entry->qualifiedCppName()));
|
|
1949 return 0;
|
|
1950 }
|
|
1951
|
|
1952 return meta_class->findEnum(enum_name);
|
|
1953 }
|
|
1954
|
|
1955 AbstractMetaEnumValue *AbstractMetaEnumValueList::find(const QString &name) const
|
|
1956 {
|
|
1957 for (int i=0; i<size(); ++i) {
|
|
1958 if (name == at(i)->name())
|
|
1959 return at(i);
|
|
1960 }
|
|
1961 return 0;
|
|
1962 }
|
|
1963
|
|
1964 AbstractMetaEnumValue *AbstractMetaClassList::findEnumValue(const QString &name) const
|
|
1965 {
|
|
1966 QStringList lst = name.split(QLatin1String("::"));
|
|
1967
|
|
1968 Q_ASSERT_X(lst.size() == 2, "AbstractMetaClassList::findEnumValue()", "Expected qualified enum");
|
|
1969
|
|
1970
|
|
1971 QString prefixName = lst.at(0);
|
|
1972 QString enumName = lst.at(1);
|
|
1973
|
|
1974 AbstractMetaClass *cl = findClass(prefixName);
|
|
1975 if (cl)
|
|
1976 return cl->findEnumValue(enumName, 0);
|
|
1977
|
|
1978 ReportHandler::warning(QString("no matching enum '%1'").arg(name));
|
|
1979 return 0;
|
|
1980 }
|
|
1981
|
|
1982 /*!
|
|
1983 * Searches the list after a class that mathces \a name; either as
|
|
1984 * C++, Java base name or complete Java package.class name.
|
|
1985 */
|
|
1986
|
|
1987 AbstractMetaClass *AbstractMetaClassList::findClass(const QString &name) const
|
|
1988 {
|
|
1989 if (name.isEmpty())
|
|
1990 return 0;
|
|
1991
|
|
1992 foreach (AbstractMetaClass *c, *this) {
|
|
1993 if (c->qualifiedCppName() == name)
|
|
1994 return c;
|
|
1995 }
|
|
1996
|
|
1997 foreach (AbstractMetaClass *c, *this) {
|
|
1998 if (c->fullName() == name)
|
|
1999 return c;
|
|
2000 }
|
|
2001
|
|
2002 foreach (AbstractMetaClass *c, *this) {
|
|
2003 if (c->name() == name)
|
|
2004 return c;
|
|
2005 }
|
|
2006
|
|
2007 return 0;
|
|
2008 }
|
|
2009
|
|
2010 ArgumentReplace *ArgumentReplace::m_instance = 0;
|
|
2011
|
|
2012 ArgumentReplace::ArgumentReplace()
|
|
2013 {
|
|
2014 }
|
|
2015
|
|
2016 void ArgumentReplace::init()
|
|
2017 {
|
|
2018 if (m_instance)
|
|
2019 return;
|
|
2020
|
|
2021 m_instance = new ArgumentReplace();
|
|
2022 m_instance->data["version"] = "_version";
|
|
2023 m_instance->data["parent"] = "_parent";
|
|
2024 m_instance->data["delegate"] = "_delegate";
|
|
2025 m_instance->data["align"] = "_align";
|
|
2026 m_instance->data["in"] = "_in";
|
|
2027 m_instance->data["out"] = "_out";
|
|
2028 m_instance->data["scope"] = "_scope";
|
|
2029 m_instance->data["default"] = "_default";
|
39
|
2030 m_instance->data["body"] = "_body";
|
1
|
2031 }
|
|
2032
|
|
2033 QString ArgumentReplace::translate(QString arg)
|
|
2034 {
|
|
2035 if (m_instance->data.contains(arg))
|
|
2036 return m_instance->data[arg];
|
|
2037 else
|
|
2038 return arg;
|
|
2039 }
|