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"
|
288
|
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
|
288
|
672 QString AbstractMetaFunction::minimalSignature(int reduce) const
|
1
|
673 {
|
288
|
674 if (!m_cached_minimal_signature.isEmpty() && !reduce)
|
1
|
675 return m_cached_minimal_signature;
|
|
676
|
|
677 QString minimalSignature = originalName() + "(";
|
|
678 AbstractMetaArgumentList arguments = this->arguments();
|
288
|
679 int argsCount = arguments.count() - reduce;
|
|
680 for (int i=0; i<argsCount; ++i) {
|
1
|
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());
|
288
|
693 if(!reduce)
|
|
694 m_cached_minimal_signature = minimalSignature;
|
1
|
695
|
|
696 return minimalSignature;
|
|
697 }
|
|
698
|
|
699 FunctionModificationList AbstractMetaFunction::modifications(const AbstractMetaClass *implementor) const
|
|
700 {
|
|
701 Q_ASSERT(implementor);
|
|
702 return implementor->typeEntry()->functionModifications(minimalSignature());
|
|
703 }
|
|
704
|
|
705 bool AbstractMetaFunction::hasModifications(const AbstractMetaClass *implementor) const
|
|
706 {
|
|
707 FunctionModificationList mods = modifications(implementor);
|
|
708 return mods.count() > 0;
|
|
709 }
|
|
710
|
|
711 QString AbstractMetaFunction::modifiedName() const
|
|
712 {
|
|
713 if (m_cached_modified_name.isEmpty()) {
|
|
714 FunctionModificationList mods = modifications(implementingClass());
|
|
715 foreach (FunctionModification mod, mods) {
|
|
716 if (mod.isRenameModifier()) {
|
|
717 m_cached_modified_name = mod.renamedToName;
|
|
718 break;
|
|
719 }
|
|
720 }
|
|
721 if (m_cached_modified_name.isEmpty())
|
|
722 m_cached_modified_name = name();
|
|
723 }
|
|
724 return m_cached_modified_name;
|
|
725 }
|
|
726
|
|
727 QString AbstractMetaFunction::targetLangSignature(bool minimal) const
|
|
728 {
|
|
729 QString s;
|
|
730
|
|
731 // Attributes...
|
|
732 if (!minimal) {
|
|
733 if (isPublic()) s += "public ";
|
|
734 else if (isProtected()) s += "protected ";
|
|
735 else if (isPrivate()) s += "private ";
|
|
736
|
|
737 // if (isNative()) s += "native ";
|
|
738 // else
|
|
739 if (isFinalInTargetLang()) s += "final ";
|
|
740 else if (isAbstract()) s += "abstract ";
|
|
741
|
|
742 if (isStatic()) s += "static ";
|
|
743
|
|
744 // Return type
|
|
745 if (type())
|
|
746 s += type()->fullName() + " ";
|
|
747 else
|
|
748 s += "void ";
|
|
749 }
|
|
750
|
|
751 s += name();
|
|
752 s += "(";
|
|
753
|
|
754 for (int i=0; i<m_arguments.size(); ++i) {
|
|
755 if (i != 0) {
|
|
756 s += ",";
|
|
757 if (!minimal)
|
|
758 s += QLatin1Char(' ');
|
|
759 }
|
|
760 s += m_arguments.at(i)->type()->fullName();
|
|
761
|
|
762 if (!minimal) {
|
|
763 s += " ";
|
|
764 s += m_arguments.at(i)->argumentName();
|
|
765 }
|
|
766 }
|
|
767
|
|
768 s += ")";
|
|
769
|
|
770 return s;
|
|
771 }
|
|
772
|
|
773
|
|
774 bool function_sorter(AbstractMetaFunction *a, AbstractMetaFunction *b)
|
|
775 {
|
|
776 return a->signature() < b->signature();
|
|
777 }
|
|
778
|
|
779 /*******************************************************************************
|
|
780 * AbstractMetaClass
|
|
781 */
|
|
782 AbstractMetaClass::~AbstractMetaClass()
|
|
783 {
|
|
784 qDeleteAll(m_functions);
|
|
785 qDeleteAll(m_fields);
|
|
786 }
|
|
787
|
|
788 /*AbstractMetaClass *AbstractMetaClass::copy() const
|
|
789 {
|
|
790 AbstractMetaClass *cls = new AbstractMetaClass;
|
|
791 cls->setAttributes(attributes());
|
|
792 cls->setBaseClass(baseClass());
|
|
793 cls->setTypeEntry(typeEntry());
|
|
794 foreach (AbstractMetaFunction *function, functions()) {
|
|
795 AbstractMetaFunction *copy = function->copy();
|
|
796 function->setImplementingClass(cls);
|
|
797 cls->addFunction(copy);
|
|
798 }
|
|
799 cls->setEnums(enums());
|
|
800 foreach (const AbstractMetaField *field, fields()) {
|
|
801 AbstractMetaField *copy = field->copy();
|
|
802 copy->setEnclosingClass(cls);
|
|
803 cls->addField(copy);
|
|
804 }
|
|
805 cls->setInterfaces(interfaces());
|
|
806
|
|
807 return cls;
|
|
808 }*/
|
|
809
|
|
810 /*******************************************************************************
|
|
811 * Returns true if this class is a subclass of the given class
|
|
812 */
|
|
813 bool AbstractMetaClass::inheritsFrom(const AbstractMetaClass *cls) const
|
|
814 {
|
|
815 Q_ASSERT(cls != 0);
|
|
816
|
|
817 const AbstractMetaClass *clazz = this;
|
|
818 while (clazz != 0) {
|
|
819 if (clazz == cls)
|
|
820 return true;
|
|
821
|
|
822 clazz = clazz->baseClass();
|
|
823 }
|
|
824
|
|
825 return false;
|
|
826 }
|
|
827
|
|
828 /*******************************************************************************
|
|
829 * Constructs an interface based on the functions and enums in this
|
|
830 * class and returns it...
|
|
831 */
|
|
832 AbstractMetaClass *AbstractMetaClass::extractInterface()
|
|
833 {
|
|
834 Q_ASSERT(typeEntry()->designatedInterface());
|
|
835
|
|
836 if (m_extracted_interface == 0) {
|
|
837 AbstractMetaClass *iface = new AbstractMetaClass;
|
|
838 iface->setAttributes(attributes());
|
|
839 iface->setBaseClass(0);
|
|
840 iface->setPrimaryInterfaceImplementor(this);
|
|
841
|
|
842 iface->setTypeEntry(typeEntry()->designatedInterface());
|
|
843
|
|
844 foreach (AbstractMetaFunction *function, functions()) {
|
|
845 if (!function->isConstructor())
|
|
846 iface->addFunction(function->copy());
|
|
847 }
|
|
848
|
|
849 // iface->setEnums(enums());
|
|
850 // setEnums(AbstractMetaEnumList());
|
|
851
|
|
852 foreach (const AbstractMetaField *field, fields()) {
|
|
853 if (field->isPublic()) {
|
|
854 AbstractMetaField *new_field = field->copy();
|
|
855 new_field->setEnclosingClass(iface);
|
|
856 iface->addField(new_field);
|
|
857 }
|
|
858 }
|
|
859
|
|
860 m_extracted_interface = iface;
|
|
861 addInterface(iface);
|
|
862 }
|
|
863
|
|
864 return m_extracted_interface;
|
|
865 }
|
|
866
|
|
867 /*******************************************************************************
|
|
868 * Returns a list of all the functions with a given name
|
|
869 */
|
|
870 AbstractMetaFunctionList AbstractMetaClass::queryFunctionsByName(const QString &name) const
|
|
871 {
|
|
872 AbstractMetaFunctionList returned;
|
|
873 AbstractMetaFunctionList functions = this->functions();
|
|
874 foreach (AbstractMetaFunction *function, functions) {
|
|
875 if (function->name() == name)
|
|
876 returned.append(function);
|
|
877 }
|
|
878
|
|
879 return returned;
|
|
880 }
|
|
881
|
|
882 /*******************************************************************************
|
|
883 * Returns all reference count modifications for any function in the class
|
|
884 */
|
|
885 QList<ReferenceCount> AbstractMetaClass::referenceCounts() const
|
|
886 {
|
|
887 QList<ReferenceCount> returned;
|
|
888
|
|
889 AbstractMetaFunctionList functions = this->functions();
|
|
890 foreach (AbstractMetaFunction *function, functions) {
|
|
891 returned += function->referenceCounts(this);
|
|
892 }
|
|
893
|
|
894 return returned;
|
|
895 }
|
|
896
|
|
897 /*******************************************************************************
|
|
898 * Returns a list of all the functions retrieved during parsing which should
|
|
899 * be added to the Java API.
|
|
900 */
|
|
901 AbstractMetaFunctionList AbstractMetaClass::functionsInTargetLang() const
|
|
902 {
|
|
903 int default_flags = NormalFunctions | Visible | NotRemovedFromTargetLang;
|
|
904
|
|
905 // Interfaces don't implement functions
|
|
906 default_flags |= isInterface() ? 0 : ClassImplements;
|
|
907
|
|
908 // Only public functions in final classes
|
|
909 // default_flags |= isFinal() ? WasPublic : 0;
|
|
910 int public_flags = isFinal() ? WasPublic : 0;
|
|
911
|
|
912 // Constructors
|
|
913 AbstractMetaFunctionList returned = queryFunctions(Constructors | default_flags | public_flags);
|
|
914
|
|
915 // Final functions
|
|
916 returned += queryFunctions(FinalInTargetLangFunctions | NonStaticFunctions | default_flags | public_flags);
|
|
917
|
|
918 // Virtual functions
|
|
919 returned += queryFunctions(VirtualInTargetLangFunctions | NonStaticFunctions | default_flags | public_flags);
|
|
920
|
|
921 // Static functions
|
|
922 returned += queryFunctions(StaticFunctions | default_flags | public_flags);
|
|
923
|
|
924 // Empty, private functions, since they aren't caught by the other ones
|
|
925 returned += queryFunctions(Empty | Invisible);
|
|
926
|
|
927 return returned;
|
|
928 }
|
|
929
|
|
930 AbstractMetaFunctionList AbstractMetaClass::virtualFunctions() const
|
|
931 {
|
|
932 AbstractMetaFunctionList list = functionsInShellClass();
|
|
933
|
|
934 AbstractMetaFunctionList returned;
|
|
935 foreach (AbstractMetaFunction *f, list) {
|
|
936 if (!f->isFinalInCpp() || f->isVirtualSlot())
|
|
937 returned += f;
|
|
938 }
|
|
939
|
|
940 return returned;
|
|
941 }
|
|
942
|
|
943 AbstractMetaFunctionList AbstractMetaClass::nonVirtualShellFunctions() const
|
|
944 {
|
|
945 AbstractMetaFunctionList list = functionsInShellClass();
|
|
946 AbstractMetaFunctionList returned;
|
|
947 foreach (AbstractMetaFunction *f, list) {
|
|
948 if (f->isFinalInCpp() && !f->isVirtualSlot())
|
|
949 returned += f;
|
|
950 }
|
|
951
|
|
952 return returned;
|
|
953 }
|
|
954
|
|
955 /*******************************************************************************
|
|
956 * Returns a list of all functions that should be declared and implemented in
|
|
957 * the shell class which is generated as a wrapper on top of the actual C++ class
|
|
958 */
|
|
959 AbstractMetaFunctionList AbstractMetaClass::functionsInShellClass() const
|
|
960 {
|
|
961 // Only functions and only protected and public functions
|
|
962 int default_flags = NormalFunctions | Visible | WasVisible | NotRemovedFromShell;
|
|
963
|
|
964 // All virtual functions
|
|
965 AbstractMetaFunctionList returned = queryFunctions(VirtualFunctions | default_flags);
|
|
966
|
|
967 // All functions explicitly set to be implemented by the shell class
|
|
968 // (mainly superclass functions that are hidden by other declarations)
|
|
969 returned += queryFunctions(ForcedShellFunctions | default_flags);
|
|
970
|
|
971 // All functions explicitly set to be virtual slots
|
|
972 returned += queryFunctions(VirtualSlots | default_flags);
|
|
973
|
|
974 return returned;
|
|
975 }
|
|
976
|
|
977 /*******************************************************************************
|
|
978 * Returns a list of all functions that require a public override function to
|
|
979 * be generated in the shell class. This includes all functions that were originally
|
|
980 * protected in the superclass.
|
|
981 */
|
|
982 AbstractMetaFunctionList AbstractMetaClass::publicOverrideFunctions() const
|
|
983 {
|
|
984 return queryFunctions(NormalFunctions | WasProtected | FinalInCppFunctions | NotRemovedFromTargetLang)
|
|
985 + queryFunctions(Signals | WasProtected | FinalInCppFunctions | NotRemovedFromTargetLang);
|
|
986 }
|
|
987
|
|
988 AbstractMetaFunctionList AbstractMetaClass::virtualOverrideFunctions() const
|
|
989 {
|
|
990 return queryFunctions(NormalFunctions | NonEmptyFunctions | Visible | VirtualInCppFunctions | NotRemovedFromShell) +
|
|
991 queryFunctions(Signals | NonEmptyFunctions | Visible | VirtualInCppFunctions | NotRemovedFromShell);
|
|
992 }
|
|
993
|
|
994 void AbstractMetaClass::sortFunctions()
|
|
995 {
|
|
996 qSort(m_functions.begin(), m_functions.end(), function_sorter);
|
|
997 }
|
|
998
|
|
999 void AbstractMetaClass::setFunctions(const AbstractMetaFunctionList &functions)
|
|
1000 {
|
|
1001 m_functions = functions;
|
|
1002
|
|
1003 // Functions must be sorted by name before next loop
|
|
1004 sortFunctions();
|
|
1005
|
|
1006 QString currentName;
|
|
1007 bool hasVirtuals = false;
|
|
1008 AbstractMetaFunctionList final_functions;
|
|
1009 foreach (AbstractMetaFunction *f, m_functions) {
|
|
1010 f->setOwnerClass(this);
|
|
1011
|
|
1012 m_has_virtual_slots |= f->isVirtualSlot();
|
|
1013 m_has_virtuals |= !f->isFinal() || f->isVirtualSlot();
|
|
1014 m_has_nonpublic |= !f->isPublic();
|
|
1015
|
|
1016 // If we have non-virtual overloads of a virtual function, we have to implement
|
|
1017 // all the overloads in the shell class to override the hiding rule
|
|
1018 if (currentName == f->name()) {
|
|
1019 hasVirtuals = hasVirtuals || !f->isFinal();
|
|
1020 if (f->isFinal())
|
|
1021 final_functions += f;
|
|
1022 } else {
|
|
1023 if (hasVirtuals && final_functions.size() > 0) {
|
|
1024 foreach (AbstractMetaFunction *final_function, final_functions) {
|
|
1025 *final_function += AbstractMetaAttributes::ForceShellImplementation;
|
|
1026
|
|
1027 QString warn = QString("hiding of function '%1' in class '%2'")
|
|
1028 .arg(final_function->name()).arg(name());
|
|
1029 ReportHandler::warning(warn);
|
|
1030 }
|
|
1031 }
|
|
1032
|
|
1033 hasVirtuals = !f->isFinal();
|
|
1034 final_functions.clear();
|
|
1035 if (f->isFinal())
|
|
1036 final_functions += f;
|
|
1037 currentName = f->name();
|
|
1038 }
|
|
1039 }
|
|
1040
|
|
1041 #ifndef QT_NO_DEBUG
|
|
1042 bool duplicate_function = false;
|
|
1043 for (int j=0; j<m_functions.size(); ++j) {
|
|
1044 FunctionModificationList mods = m_functions.at(j)->modifications(m_functions.at(j)->implementingClass());
|
|
1045
|
|
1046 bool removed = false;
|
|
1047 foreach (const FunctionModification &mod, mods) {
|
|
1048 if (mod.isRemoveModifier()) {
|
|
1049 removed = true;
|
|
1050 break ;
|
|
1051 }
|
|
1052 }
|
|
1053 if (removed)
|
|
1054 continue ;
|
|
1055
|
|
1056 for (int i=0; i<m_functions.size() - 1; ++i) {
|
|
1057 if (j == i)
|
|
1058 continue;
|
|
1059
|
|
1060 mods = m_functions.at(i)->modifications(m_functions.at(i)->implementingClass());
|
|
1061 bool removed = false;
|
|
1062 foreach (const FunctionModification &mod, mods) {
|
|
1063 if (mod.isRemoveModifier()) {
|
|
1064 removed = true;
|
|
1065 break ;
|
|
1066 }
|
|
1067 }
|
|
1068 if (removed)
|
|
1069 continue ;
|
|
1070
|
|
1071 uint cmp = m_functions.at(i)->compareTo(m_functions.at(j));
|
|
1072 if ((cmp & AbstractMetaFunction::EqualName) && (cmp & AbstractMetaFunction::EqualArguments)) {
|
|
1073 printf("%s.%s mostly equal to %s.%s\n",
|
|
1074 qPrintable(m_functions.at(i)->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1075 qPrintable(m_functions.at(i)->signature()),
|
|
1076 qPrintable(m_functions.at(j)->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1077 qPrintable(m_functions.at(j)->signature()));
|
|
1078 duplicate_function = true;
|
|
1079 }
|
|
1080 }
|
|
1081 }
|
|
1082 //Q_ASSERT(!duplicate_function);
|
|
1083 #endif
|
|
1084 }
|
|
1085
|
|
1086 bool AbstractMetaClass::hasFieldAccessors() const
|
|
1087 {
|
|
1088 foreach (const AbstractMetaField *field, fields()) {
|
|
1089 if (field->getter() || field->setter())
|
|
1090 return true;
|
|
1091 }
|
|
1092
|
|
1093 return false;
|
|
1094 }
|
|
1095
|
|
1096 bool AbstractMetaClass::hasDefaultToStringFunction() const
|
|
1097 {
|
|
1098 foreach (AbstractMetaFunction *f, queryFunctionsByName("toString")) {
|
|
1099 if (f->actualMinimumArgumentCount() == 0) {
|
|
1100 return true;
|
|
1101 }
|
|
1102
|
|
1103 }
|
|
1104 return false;
|
|
1105 }
|
|
1106
|
|
1107 void AbstractMetaClass::addFunction(AbstractMetaFunction *function)
|
|
1108 {
|
|
1109 function->setOwnerClass(this);
|
|
1110
|
|
1111 if (!function->isDestructor()) {
|
|
1112 m_functions << function;
|
|
1113 qSort(m_functions.begin(), m_functions.end(), function_sorter);
|
|
1114 }
|
|
1115
|
|
1116
|
|
1117 m_has_virtual_slots |= function->isVirtualSlot();
|
|
1118 m_has_virtuals |= !function->isFinal() || function->isVirtualSlot();
|
|
1119 m_has_nonpublic |= !function->isPublic();
|
|
1120 }
|
|
1121
|
|
1122 bool AbstractMetaClass::hasSignal(const AbstractMetaFunction *other) const
|
|
1123 {
|
|
1124 if (!other->isSignal())
|
|
1125 return false;
|
|
1126
|
|
1127 foreach (const AbstractMetaFunction *f, functions()) {
|
|
1128 if (f->isSignal() && f->compareTo(other) & AbstractMetaFunction::EqualName)
|
|
1129 return other->modifiedName() == f->modifiedName();
|
|
1130 }
|
|
1131
|
|
1132 return false;
|
|
1133 }
|
|
1134
|
|
1135
|
|
1136 QString AbstractMetaClass::name() const
|
|
1137 {
|
|
1138 return QString(m_type_entry->targetLangName()).replace("::", "_");
|
|
1139 }
|
|
1140
|
|
1141 bool AbstractMetaClass::hasFunction(const QString &str) const
|
|
1142 {
|
|
1143 foreach (const AbstractMetaFunction *f, functions())
|
|
1144 if (f->name() == str)
|
|
1145 return true;
|
|
1146 return false;
|
|
1147 }
|
|
1148
|
|
1149 /* Returns true if this class has one or more functions that are
|
|
1150 protected. If a class has protected members we need to generate a
|
|
1151 shell class with public accessors to the protected functions, so
|
|
1152 they can be called from the native functions.
|
|
1153 */
|
|
1154 bool AbstractMetaClass::hasProtectedFunctions() const {
|
|
1155 foreach (AbstractMetaFunction *func, m_functions) {
|
|
1156 if (func->isProtected())
|
|
1157 return true;
|
|
1158 }
|
|
1159 return false;
|
|
1160 }
|
|
1161
|
|
1162 bool AbstractMetaClass::generateShellClass() const
|
|
1163 {
|
|
1164 return m_force_shell_class ||
|
|
1165 (!isFinal()
|
|
1166 && (hasVirtualFunctions()
|
|
1167 || hasProtectedFunctions()
|
|
1168 || hasFieldAccessors()
|
|
1169 || typeEntry()->isObject())); // qtd2 for being more consistent
|
|
1170 }
|
|
1171
|
|
1172 QPropertySpec *AbstractMetaClass::propertySpecForRead(const QString &name) const
|
|
1173 {
|
|
1174 for (int i=0; i<m_property_specs.size(); ++i)
|
|
1175 if (name == m_property_specs.at(i)->read())
|
|
1176 return m_property_specs.at(i);
|
|
1177 return 0;
|
|
1178 }
|
|
1179
|
|
1180 QPropertySpec *AbstractMetaClass::propertySpecForWrite(const QString &name) const
|
|
1181 {
|
|
1182 for (int i=0; i<m_property_specs.size(); ++i)
|
|
1183 if (name == m_property_specs.at(i)->write())
|
|
1184 return m_property_specs.at(i);
|
|
1185 return 0;
|
|
1186 }
|
|
1187
|
|
1188 QPropertySpec *AbstractMetaClass::propertySpecForReset(const QString &name) const
|
|
1189 {
|
|
1190 for (int i=0; i<m_property_specs.size(); ++i) {
|
|
1191 if (name == m_property_specs.at(i)->reset())
|
|
1192 return m_property_specs.at(i);
|
|
1193 }
|
|
1194 return 0;
|
|
1195 }
|
|
1196
|
|
1197
|
|
1198
|
|
1199 static bool functions_contains(const AbstractMetaFunctionList &l, const AbstractMetaFunction *func)
|
|
1200 {
|
|
1201 foreach (const AbstractMetaFunction *f, l) {
|
|
1202 if ((f->compareTo(func) & AbstractMetaFunction::PrettySimilar) == AbstractMetaFunction::PrettySimilar)
|
|
1203 return true;
|
|
1204 }
|
|
1205 return false;
|
|
1206 }
|
|
1207
|
|
1208 AbstractMetaField::AbstractMetaField() : m_getter(0), m_setter(0), m_class(0)
|
|
1209 {
|
|
1210 }
|
|
1211
|
|
1212 AbstractMetaField::~AbstractMetaField()
|
|
1213 {
|
|
1214 delete m_setter;
|
|
1215 delete m_getter;
|
|
1216 }
|
|
1217 ushort painters; // refcount
|
|
1218 AbstractMetaField *AbstractMetaField::copy() const
|
|
1219 {
|
|
1220 AbstractMetaField *returned = new AbstractMetaField;
|
|
1221 returned->setEnclosingClass(0);
|
|
1222 returned->setAttributes(attributes());
|
|
1223 returned->setName(name());
|
|
1224 returned->setType(type()->copy());
|
|
1225 returned->setOriginalAttributes(originalAttributes());
|
|
1226
|
|
1227 return returned;
|
|
1228 }
|
|
1229
|
|
1230 static QString upCaseFirst(const QString &str) {
|
|
1231 Q_ASSERT(!str.isEmpty());
|
|
1232 QString s = str;
|
|
1233 s[0] = s.at(0).toUpper();
|
|
1234 return s;
|
|
1235 }
|
|
1236
|
|
1237 static AbstractMetaFunction *createXetter(const AbstractMetaField *g, const QString &name, uint type) {
|
|
1238 AbstractMetaFunction *f = new AbstractMetaFunction;
|
|
1239
|
|
1240
|
|
1241
|
|
1242 f->setName(name);
|
|
1243 f->setOriginalName(name);
|
|
1244 f->setOwnerClass(g->enclosingClass());
|
|
1245 f->setImplementingClass(g->enclosingClass());
|
|
1246 f->setDeclaringClass(g->enclosingClass());
|
|
1247
|
|
1248 uint attr = AbstractMetaAttributes::Native
|
|
1249 | AbstractMetaAttributes::Final
|
|
1250 | type;
|
|
1251 if (g->isStatic())
|
|
1252 attr |= AbstractMetaAttributes::Static;
|
|
1253 if (g->isPublic())
|
|
1254 attr |= AbstractMetaAttributes::Public;
|
|
1255 else if (g->isProtected())
|
|
1256 attr |= AbstractMetaAttributes::Protected;
|
|
1257 else
|
|
1258 attr |= AbstractMetaAttributes::Private;
|
|
1259 f->setAttributes(attr);
|
|
1260 f->setOriginalAttributes(attr);
|
|
1261
|
|
1262 FieldModificationList mods = g->modifications();
|
|
1263 foreach (FieldModification mod, mods) {
|
|
1264 if (mod.isRenameModifier())
|
|
1265 f->setName(mod.renamedTo());
|
|
1266 if (mod.isAccessModifier()) {
|
|
1267 if (mod.isPrivate())
|
|
1268 f->setVisibility(AbstractMetaAttributes::Private);
|
|
1269 else if (mod.isProtected())
|
|
1270 f->setVisibility(AbstractMetaAttributes::Protected);
|
|
1271 else if (mod.isPublic())
|
|
1272 f->setVisibility(AbstractMetaAttributes::Public);
|
|
1273 else if (mod.isFriendly())
|
|
1274 f->setVisibility(AbstractMetaAttributes::Friendly);
|
|
1275 }
|
|
1276
|
|
1277 }
|
|
1278 return f;
|
|
1279 }
|
|
1280
|
|
1281 FieldModificationList AbstractMetaField::modifications() const
|
|
1282 {
|
|
1283 FieldModificationList mods = enclosingClass()->typeEntry()->fieldModifications();
|
|
1284 FieldModificationList returned;
|
|
1285
|
|
1286 foreach (FieldModification mod, mods) {
|
|
1287 if (mod.name == name())
|
|
1288 returned += mod;
|
|
1289 }
|
|
1290
|
|
1291 return returned;
|
|
1292 }
|
|
1293
|
|
1294 const AbstractMetaFunction *AbstractMetaField::setter() const
|
|
1295 {
|
|
1296 if (m_setter == 0) {
|
|
1297 m_setter = createXetter(this,
|
|
1298 "set" + upCaseFirst(name()),
|
|
1299 AbstractMetaAttributes::SetterFunction);
|
|
1300 AbstractMetaArgumentList arguments;
|
|
1301 AbstractMetaArgument *argument = new AbstractMetaArgument;
|
|
1302 argument->setType(type()->copy());
|
|
1303 argument->setName(name());
|
|
1304 arguments.append(argument);
|
|
1305 m_setter->setArguments(arguments);
|
|
1306 }
|
|
1307 return m_setter;
|
|
1308 }
|
|
1309
|
|
1310 const AbstractMetaFunction *AbstractMetaField::getter() const
|
|
1311 {
|
|
1312 if (m_getter == 0) {
|
|
1313 m_getter = createXetter(this,
|
|
1314 name(),
|
|
1315 AbstractMetaAttributes::GetterFunction);
|
|
1316 m_getter->setType(type());
|
|
1317 }
|
|
1318
|
|
1319 return m_getter;
|
|
1320 }
|
|
1321
|
|
1322
|
|
1323 bool AbstractMetaClass::hasConstructors() const
|
|
1324 {
|
|
1325 return queryFunctions(Constructors).size() != 0;
|
|
1326 }
|
|
1327
|
|
1328 void AbstractMetaClass::addDefaultConstructor()
|
|
1329 {
|
|
1330 AbstractMetaFunction *f = new AbstractMetaFunction;
|
|
1331 f->setName(name());
|
|
1332 f->setOwnerClass(this);
|
|
1333 f->setFunctionType(AbstractMetaFunction::ConstructorFunction);
|
|
1334 f->setArguments(AbstractMetaArgumentList());
|
|
1335 f->setDeclaringClass(this);
|
|
1336
|
|
1337 uint attr = AbstractMetaAttributes::Native;
|
|
1338 attr |= AbstractMetaAttributes::Public;
|
|
1339 attr |= AbstractMetaAttributes::Final; // qtd otherwise added constructor is virtual which in fact it is not
|
|
1340 f->setAttributes(attr);
|
|
1341 f->setImplementingClass(this);
|
|
1342 f->setOriginalAttributes(f->attributes());
|
|
1343
|
|
1344 addFunction(f);
|
|
1345 }
|
|
1346
|
|
1347 bool AbstractMetaClass::hasFunction(const AbstractMetaFunction *f) const
|
|
1348 {
|
|
1349 return functions_contains(m_functions, f);
|
|
1350 }
|
|
1351
|
|
1352 /* Goes through the list of functions and returns a list of all
|
|
1353 functions matching all of the criteria in \a query.
|
|
1354 */
|
|
1355
|
|
1356 AbstractMetaFunctionList AbstractMetaClass::queryFunctions(uint query) const
|
|
1357 {
|
|
1358 AbstractMetaFunctionList functions;
|
|
1359
|
|
1360 foreach (AbstractMetaFunction *f, m_functions) {
|
|
1361
|
|
1362 if ((query & VirtualSlots) && !f->isVirtualSlot())
|
|
1363 continue;
|
|
1364
|
|
1365 if ((query & NotRemovedFromTargetLang) && f->isRemovedFrom(f->implementingClass(), TypeSystem::TargetLangCode)) {
|
|
1366 continue;
|
|
1367 }
|
|
1368
|
|
1369 if ((query & NotRemovedFromTargetLang) && !f->isFinal() && f->isRemovedFrom(f->declaringClass(), TypeSystem::TargetLangCode)) {
|
|
1370 continue;
|
|
1371 }
|
|
1372
|
|
1373 if ((query & NotRemovedFromShell) && f->isRemovedFrom(f->implementingClass(), TypeSystem::ShellCode)) {
|
|
1374 continue;
|
|
1375 }
|
|
1376
|
|
1377 if ((query & NotRemovedFromShell) && !f->isFinal() && f->isRemovedFrom(f->declaringClass(), TypeSystem::ShellCode)) {
|
|
1378 continue;
|
|
1379 }
|
|
1380
|
|
1381 if ((query & Visible) && f->isPrivate()) {
|
|
1382 continue;
|
|
1383 }
|
|
1384
|
|
1385 if ((query & VirtualInTargetLangFunctions) && f->isFinalInTargetLang()) {
|
|
1386 continue;
|
|
1387 }
|
|
1388
|
|
1389 if ((query & Invisible) && !f->isPrivate()) {
|
|
1390 continue;
|
|
1391 }
|
|
1392
|
|
1393 if ((query & Empty) && !f->isEmptyFunction()) {
|
|
1394 continue;
|
|
1395 }
|
|
1396
|
|
1397 if ((query & WasPublic) && !f->wasPublic()) {
|
|
1398 continue;
|
|
1399 }
|
|
1400
|
|
1401 if ((query & WasVisible) && f->wasPrivate()) {
|
|
1402 continue;
|
|
1403 }
|
|
1404
|
|
1405 if ((query & WasProtected) && !f->wasProtected()) {
|
|
1406 continue;
|
|
1407 }
|
|
1408
|
|
1409 if ((query & ClassImplements) && f->ownerClass() != f->implementingClass()) {
|
|
1410 continue;
|
|
1411 }
|
|
1412
|
|
1413 if ((query & Inconsistent) && (f->isFinalInTargetLang() || !f->isFinalInCpp() || f->isStatic())) {
|
|
1414 continue;
|
|
1415 }
|
|
1416
|
|
1417 if ((query & FinalInTargetLangFunctions) && !f->isFinalInTargetLang()) {
|
|
1418 continue;
|
|
1419 }
|
|
1420
|
|
1421 if ((query & FinalInCppFunctions) && !f->isFinalInCpp()) {
|
|
1422 continue;
|
|
1423 }
|
|
1424
|
|
1425 if ((query & VirtualInCppFunctions) && f->isFinalInCpp()) {
|
|
1426 continue;
|
|
1427 }
|
|
1428
|
|
1429 if ((query & Signals) && (!f->isSignal())) {
|
|
1430 continue;
|
|
1431 }
|
|
1432
|
|
1433 if ((query & ForcedShellFunctions)
|
|
1434 && (!f->isForcedShellImplementation()
|
|
1435 || !f->isFinal())) {
|
|
1436 continue;
|
|
1437 }
|
|
1438
|
|
1439 if ((query & Constructors) && (!f->isConstructor()
|
|
1440 || f->ownerClass() != f->implementingClass())
|
|
1441 || f->isConstructor() && (query & Constructors) == 0) {
|
|
1442 continue;
|
|
1443 }
|
|
1444
|
|
1445 // Destructors are never included in the functions of a class currently
|
|
1446 /*
|
|
1447 if ((query & Destructors) && (!f->isDestructor()
|
|
1448 || f->ownerClass() != f->implementingClass())
|
|
1449 || f->isDestructor() && (query & Destructors) == 0) {
|
|
1450 continue;
|
|
1451 }*/
|
|
1452
|
|
1453 if ((query & VirtualFunctions) && (f->isFinal() || f->isSignal() || f->isStatic())) {
|
|
1454 continue;
|
|
1455 }
|
|
1456
|
|
1457 if ((query & StaticFunctions) && (!f->isStatic() || f->isSignal())) {
|
|
1458 continue;
|
|
1459 }
|
|
1460
|
|
1461 if ((query & NonStaticFunctions) && (f->isStatic())) {
|
|
1462 continue;
|
|
1463 }
|
|
1464
|
|
1465 if ((query & NonEmptyFunctions) && (f->isEmptyFunction())) {
|
|
1466 continue;
|
|
1467 }
|
|
1468
|
|
1469 if ((query & NormalFunctions) && (f->isSignal())) {
|
|
1470 continue;
|
|
1471 }
|
|
1472
|
|
1473 if ((query & AbstractFunctions) && !f->isAbstract()) {
|
|
1474 continue;
|
|
1475 }
|
|
1476
|
|
1477 functions << f;
|
|
1478 }
|
|
1479
|
|
1480 // qDebug() << "queried" << m_type_entry->qualifiedCppName() << "got" << functions.size() << "out of" << m_functions.size();
|
|
1481
|
|
1482 return functions;
|
|
1483 }
|
|
1484
|
|
1485
|
|
1486 bool AbstractMetaClass::hasInconsistentFunctions() const
|
|
1487 {
|
|
1488 return cppInconsistentFunctions().size() > 0;
|
|
1489 }
|
|
1490
|
|
1491 bool AbstractMetaClass::hasSignals() const
|
|
1492 {
|
|
1493 return cppSignalFunctions().size() > 0;
|
|
1494 }
|
|
1495
|
|
1496
|
|
1497 /**
|
|
1498 * Adds the specified interface to this class by adding all the
|
|
1499 * functions in the interface to this class.
|
|
1500 */
|
|
1501 void AbstractMetaClass::addInterface(AbstractMetaClass *interface)
|
|
1502 {
|
|
1503 Q_ASSERT(!m_interfaces.contains(interface));
|
|
1504 m_interfaces << interface;
|
|
1505
|
|
1506 if (m_extracted_interface != 0 && m_extracted_interface != interface)
|
|
1507 m_extracted_interface->addInterface(interface);
|
|
1508
|
|
1509 foreach (AbstractMetaFunction *function, interface->functions())
|
|
1510 if (!hasFunction(function) && !function->isConstructor()) {
|
|
1511 AbstractMetaFunction *cpy = function->copy();
|
|
1512 cpy->setImplementingClass(this);
|
|
1513
|
|
1514 // Setup that this function is an interface class.
|
|
1515 cpy->setInterfaceClass(interface);
|
|
1516 *cpy += AbstractMetaAttributes::InterfaceFunction;
|
|
1517
|
|
1518 // Copy the modifications in interface into the implementing classes.
|
|
1519 FunctionModificationList mods = function->modifications(interface);
|
|
1520 foreach (const FunctionModification &mod, mods) {
|
|
1521 m_type_entry->addFunctionModification(mod);
|
|
1522 }
|
|
1523
|
|
1524 // It should be mostly safe to assume that when we implement an interface
|
|
1525 // we don't "pass on" pure virtual functions to our sublcasses...
|
|
1526 // *cpy -= AbstractMetaAttributes::Abstract;
|
|
1527
|
|
1528 addFunction(cpy);
|
|
1529 }
|
|
1530 }
|
|
1531
|
|
1532
|
|
1533 void AbstractMetaClass::setInterfaces(const AbstractMetaClassList &interfaces)
|
|
1534 {
|
|
1535 m_interfaces = interfaces;
|
|
1536 }
|
|
1537
|
|
1538
|
|
1539 AbstractMetaEnum *AbstractMetaClass::findEnum(const QString &enumName)
|
|
1540 {
|
|
1541 foreach (AbstractMetaEnum *e, m_enums) {
|
|
1542 if (e->name() == enumName)
|
|
1543 return e;
|
|
1544 }
|
|
1545
|
|
1546 if (typeEntry()->designatedInterface())
|
|
1547 return extractInterface()->findEnum(enumName);
|
|
1548
|
|
1549 return 0;
|
|
1550 }
|
|
1551
|
|
1552
|
|
1553
|
|
1554
|
|
1555 /*! Recursivly searches for the enum value named \a enumValueName in
|
|
1556 this class and its superclasses and interfaces. Values belonging to
|
|
1557 \a meta_enum are excluded from the search.
|
|
1558 */
|
|
1559 AbstractMetaEnumValue *AbstractMetaClass::findEnumValue(const QString &enumValueName, AbstractMetaEnum *meta_enum)
|
|
1560 {
|
|
1561 foreach (AbstractMetaEnum *e, m_enums) {
|
|
1562 if (e == meta_enum)
|
|
1563 continue;
|
|
1564 foreach (AbstractMetaEnumValue *v, e->values()) {
|
|
1565 if (v->name() == enumValueName)
|
|
1566 return v;
|
|
1567 }
|
|
1568 }
|
|
1569
|
|
1570 if (typeEntry()->designatedInterface())
|
|
1571 return extractInterface()->findEnumValue(enumValueName, meta_enum);
|
|
1572
|
|
1573 if (baseClass() != 0)
|
|
1574 return baseClass()->findEnumValue(enumValueName, meta_enum);
|
|
1575
|
|
1576 return 0;
|
|
1577 }
|
|
1578
|
|
1579
|
|
1580 /*!
|
|
1581 * Searches through all of this class' enums for a value matching the
|
|
1582 * name \a enumValueName. The name is excluding the class/namespace
|
|
1583 * prefix. The function recursivly searches interfaces and baseclasses
|
|
1584 * of this class.
|
|
1585 */
|
|
1586 AbstractMetaEnum *AbstractMetaClass::findEnumForValue(const QString &enumValueName)
|
|
1587 {
|
|
1588 foreach (AbstractMetaEnum *e, m_enums) {
|
|
1589 foreach (AbstractMetaEnumValue *v, e->values()) {
|
|
1590 if (v->name() == enumValueName)
|
|
1591 return e;
|
|
1592 }
|
|
1593 }
|
|
1594
|
|
1595 if (typeEntry()->designatedInterface())
|
|
1596 return extractInterface()->findEnumForValue(enumValueName);
|
|
1597
|
|
1598 if (baseClass() != 0)
|
|
1599 return baseClass()->findEnumForValue(enumValueName);
|
|
1600
|
|
1601 return 0;
|
|
1602 }
|
|
1603
|
|
1604
|
|
1605 static void add_extra_include_for_type(AbstractMetaClass *meta_class, const AbstractMetaType *type)
|
|
1606 {
|
|
1607
|
|
1608 if (type == 0)
|
|
1609 return;
|
|
1610
|
|
1611 Q_ASSERT(meta_class != 0);
|
|
1612 const TypeEntry *entry = (type ? type->typeEntry() : 0);
|
|
1613 if (entry != 0 && entry->isComplex()) {
|
|
1614 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(entry);
|
|
1615 ComplexTypeEntry *class_entry = meta_class->typeEntry();
|
|
1616 if (class_entry != 0 && centry->include().isValid())
|
|
1617 class_entry->addExtraInclude(centry->include());
|
|
1618 }
|
|
1619
|
|
1620 if (type->hasInstantiations()) {
|
|
1621 QList<AbstractMetaType *> instantiations = type->instantiations();
|
|
1622 foreach (AbstractMetaType *instantiation, instantiations)
|
|
1623 add_extra_include_for_type(meta_class, instantiation);
|
|
1624 }
|
|
1625 }
|
|
1626
|
|
1627 static void add_extra_includes_for_function(AbstractMetaClass *meta_class, const AbstractMetaFunction *meta_function)
|
|
1628 {
|
|
1629 Q_ASSERT(meta_class != 0);
|
|
1630 Q_ASSERT(meta_function != 0);
|
|
1631 add_extra_include_for_type(meta_class, meta_function->type());
|
|
1632
|
|
1633 AbstractMetaArgumentList arguments = meta_function->arguments();
|
|
1634 foreach (AbstractMetaArgument *argument, arguments)
|
|
1635 add_extra_include_for_type(meta_class, argument->type());
|
|
1636 }
|
|
1637
|
|
1638 void AbstractMetaClass::fixFunctions()
|
|
1639 {
|
|
1640 if (m_functions_fixed)
|
|
1641 return;
|
|
1642 else
|
|
1643 m_functions_fixed = true;
|
|
1644
|
|
1645 AbstractMetaClass *super_class = baseClass();
|
|
1646 AbstractMetaFunctionList funcs = functions();
|
|
1647
|
|
1648 // printf("fix functions for %s\n", qPrintable(name()));
|
|
1649
|
|
1650 if (super_class != 0)
|
|
1651 super_class->fixFunctions();
|
|
1652 int iface_idx = 0;
|
|
1653 while (super_class || iface_idx < interfaces().size()) {
|
|
1654 // printf(" - base: %s\n", qPrintable(super_class->name()));
|
|
1655
|
|
1656 // Since we always traverse the complete hierarchy we are only
|
|
1657 // interrested in what each super class implements, not what
|
|
1658 // we may have propagated from their base classes again.
|
|
1659 AbstractMetaFunctionList super_funcs;
|
|
1660 if (super_class) {
|
|
1661
|
|
1662 // Super classes can never be final
|
|
1663 if (super_class->isFinalInTargetLang()) {
|
|
1664 ReportHandler::warning("Final class '" + super_class->name() + "' set to non-final, as it is extended by other classes");
|
|
1665 *super_class -= AbstractMetaAttributes::FinalInTargetLang;
|
|
1666 }
|
|
1667 super_funcs = super_class->queryFunctions(AbstractMetaClass::ClassImplements);
|
|
1668 } else {
|
|
1669 super_funcs = interfaces().at(iface_idx)->queryFunctions(AbstractMetaClass::NormalFunctions);
|
|
1670 }
|
|
1671
|
|
1672 QSet<AbstractMetaFunction *> funcs_to_add;
|
|
1673 for (int sfi=0; sfi<super_funcs.size(); ++sfi) {
|
|
1674 AbstractMetaFunction *sf = super_funcs.at(sfi);
|
|
1675
|
|
1676 if (sf->isRemovedFromAllLanguages(sf->implementingClass()))
|
|
1677 continue;
|
|
1678
|
|
1679 // we generally don't care about private functions, but we have to get the ones that are
|
|
1680 // virtual in case they override abstract functions.
|
|
1681 bool add = (sf->isNormal() || sf->isSignal() || sf->isEmptyFunction());
|
|
1682 for (int fi=0; fi<funcs.size(); ++fi) {
|
|
1683 AbstractMetaFunction *f = funcs.at(fi);
|
|
1684 if (f->isRemovedFromAllLanguages(f->implementingClass()))
|
|
1685 continue;
|
|
1686
|
|
1687 uint cmp = f->compareTo(sf);
|
|
1688
|
|
1689 if (cmp & AbstractMetaFunction::EqualModifiedName) {
|
|
1690 // printf(" - %s::%s similar to %s::%s %x vs %x\n",
|
|
1691 // qPrintable(sf->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1692 // qPrintable(sf->name()),
|
|
1693 // qPrintable(f->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1694 // qPrintable(f->name()),
|
|
1695 // sf->attributes(),
|
|
1696 // f->attributes());
|
|
1697
|
|
1698 add = false;
|
|
1699 if (cmp & AbstractMetaFunction::EqualArguments) {
|
|
1700
|
|
1701 // if (!(cmp & AbstractMetaFunction::EqualReturnType)) {
|
|
1702 // ReportHandler::warning(QString("%1::%2 and %3::%4 differ in retur type")
|
|
1703 // .arg(sf->implementingClass()->name())
|
|
1704 // .arg(sf->name())
|
|
1705 // .arg(f->implementingClass()->name())
|
|
1706 // .arg(f->name()));
|
|
1707 // }
|
|
1708
|
|
1709 // Same function, propegate virtual...
|
|
1710 if (!(cmp & AbstractMetaFunction::EqualAttributes)) {
|
|
1711 if (!f->isEmptyFunction()) {
|
|
1712 if (!sf->isFinalInCpp() && f->isFinalInCpp()) {
|
|
1713 *f -= AbstractMetaAttributes::FinalInCpp;
|
|
1714 // printf(" --- inherit virtual\n");
|
|
1715 }
|
|
1716 if (!sf->isFinalInTargetLang() && f->isFinalInTargetLang()) {
|
|
1717 *f -= AbstractMetaAttributes::FinalInTargetLang;
|
|
1718 // printf(" --- inherit virtual\n");
|
|
1719 }
|
|
1720 if (!f->isFinalInTargetLang() && f->isPrivate()) {
|
|
1721 f->setFunctionType(AbstractMetaFunction::EmptyFunction);
|
|
1722 f->setVisibility(AbstractMetaAttributes::Protected);
|
|
1723 *f += AbstractMetaAttributes::FinalInTargetLang;
|
|
1724 ReportHandler::warning(QString("private virtual function '%1' in '%2'")
|
|
1725 .arg(f->signature())
|
|
1726 .arg(f->implementingClass()->name()));
|
|
1727 }
|
|
1728 }
|
|
1729 }
|
|
1730
|
|
1731 if (f->visibility() != sf->visibility()) {
|
|
1732 QString warn = QString("visibility of function '%1' modified in class '%2'")
|
|
1733 .arg(f->name()).arg(name());
|
|
1734 ReportHandler::warning(warn);
|
|
1735
|
|
1736 // If new visibility is private, we can't
|
|
1737 // do anything. If it isn't, then we
|
|
1738 // prefer the parent class's visibility
|
|
1739 // setting for the function.
|
|
1740 if (!f->isPrivate() && !sf->isPrivate())
|
|
1741 f->setVisibility(sf->visibility());
|
|
1742
|
|
1743 // Private overrides of abstract functions have to go into the class or
|
|
1744 // the subclasses will not compile as non-abstract classes.
|
|
1745 // But they don't need to be implemented, since they can never be called.
|
|
1746 if (f->isPrivate() && sf->isAbstract()) {
|
|
1747 f->setFunctionType(AbstractMetaFunction::EmptyFunction);
|
|
1748 f->setVisibility(sf->visibility());
|
|
1749 *f += AbstractMetaAttributes::FinalInTargetLang;
|
|
1750 *f += AbstractMetaAttributes::FinalInCpp;
|
|
1751 }
|
|
1752 }
|
|
1753
|
|
1754 // Set the class which first declares this function, afawk
|
|
1755 f->setDeclaringClass(sf->declaringClass());
|
|
1756
|
|
1757 if (sf->isFinalInTargetLang() && !sf->isPrivate() && !f->isPrivate() && !sf->isStatic() && !f->isStatic()) {
|
|
1758 // Shadowed funcion, need to make base class
|
|
1759 // function non-virtual
|
|
1760 if (f->implementingClass() != sf->implementingClass() && f->implementingClass()->inheritsFrom(sf->implementingClass())) {
|
|
1761
|
|
1762 // Check whether the superclass method has been redefined to non-final
|
|
1763
|
|
1764 bool hasNonFinalModifier = false;
|
|
1765 bool isBaseImplPrivate = false;
|
|
1766 FunctionModificationList mods = sf->modifications(sf->implementingClass());
|
|
1767 foreach (FunctionModification mod, mods) {
|
|
1768 if (mod.isNonFinal()) {
|
|
1769 hasNonFinalModifier = true;
|
|
1770 break;
|
|
1771 } else if (mod.isPrivate()) {
|
|
1772 isBaseImplPrivate = true;
|
|
1773 break;
|
|
1774 }
|
|
1775 }
|
|
1776
|
|
1777 if (!hasNonFinalModifier && !isBaseImplPrivate) {
|
|
1778 ReportHandler::warning(QString::fromLatin1("Shadowing: %1::%2 and %3::%4; Java code will not compile")
|
|
1779 .arg(sf->implementingClass()->name())
|
|
1780 .arg(sf->signature())
|
|
1781 .arg(f->implementingClass()->name())
|
|
1782 .arg(f->signature()));
|
|
1783 }
|
|
1784 }
|
|
1785 }
|
|
1786
|
|
1787 }
|
|
1788
|
|
1789 if (cmp & AbstractMetaFunction::EqualDefaultValueOverload) {
|
|
1790 AbstractMetaArgumentList arguments;
|
|
1791 if (f->arguments().size() < sf->arguments().size())
|
|
1792 arguments = sf->arguments();
|
|
1793 else
|
|
1794 arguments = f->arguments();
|
|
1795 /* qtd
|
|
1796 for (int i=0; i<arguments.size(); ++i)
|
|
1797 arguments[i]->setDefaultValueExpression(QString());
|
|
1798 */ }
|
|
1799
|
|
1800
|
|
1801 // Otherwise we have function shadowing and we can
|
|
1802 // skip the thing...
|
|
1803 } else if (cmp & AbstractMetaFunction::EqualName && !sf->isSignal()) {
|
|
1804
|
|
1805 // In the case of function shadowing where the function name has been altered to
|
|
1806 // avoid conflict, we don't copy in the original.
|
|
1807 add = false;
|
|
1808 }
|
|
1809
|
|
1810 }
|
|
1811
|
|
1812 if (add)
|
|
1813 funcs_to_add << sf;
|
|
1814 }
|
|
1815
|
|
1816 foreach (AbstractMetaFunction *f, funcs_to_add)
|
|
1817 funcs << f->copy();
|
|
1818
|
|
1819 if (super_class)
|
|
1820 super_class = super_class->baseClass();
|
|
1821 else
|
|
1822 iface_idx++;
|
|
1823 }
|
|
1824
|
|
1825 bool hasPrivateConstructors = false;
|
|
1826 bool hasPublicConstructors = false;
|
|
1827 foreach (AbstractMetaFunction *func, funcs) {
|
|
1828 FunctionModificationList mods = func->modifications(this);
|
|
1829 foreach (const FunctionModification &mod, mods) {
|
|
1830 if (mod.isRenameModifier()) {
|
|
1831 // qDebug() << name() << func->originalName() << func << " from "
|
|
1832 // << func->implementingClass()->name() << "renamed to" << mod.renamedTo();
|
|
1833 func->setName(mod.renamedTo());
|
|
1834 }
|
|
1835 }
|
|
1836
|
|
1837 // Make sure class is abstract if one of the functions is
|
|
1838 if (func->isAbstract()) {
|
|
1839 (*this) += AbstractMetaAttributes::Abstract;
|
|
1840 (*this) -= AbstractMetaAttributes::Final;
|
|
1841 }
|
|
1842
|
|
1843 if (func->isConstructor()) {
|
|
1844 if (func->isPrivate())
|
|
1845 hasPrivateConstructors = true;
|
|
1846 else
|
|
1847 hasPublicConstructors = true;
|
|
1848 }
|
|
1849
|
|
1850
|
|
1851
|
|
1852 // Make sure that we include files for all classes that are in use
|
|
1853
|
|
1854 if (!func->isRemovedFrom(this, TypeSystem::ShellCode))
|
|
1855 add_extra_includes_for_function(this, func);
|
|
1856 }
|
|
1857
|
|
1858 if (hasPrivateConstructors && !hasPublicConstructors) {
|
|
1859 (*this) += AbstractMetaAttributes::Abstract;
|
|
1860 (*this) -= AbstractMetaAttributes::Final;
|
|
1861 }
|
|
1862
|
|
1863 foreach (AbstractMetaFunction *f1, funcs) {
|
|
1864 foreach (AbstractMetaFunction *f2, funcs) {
|
|
1865 if (f1 != f2) {
|
|
1866 uint cmp = f1->compareTo(f2);
|
|
1867 if ((cmp & AbstractMetaFunction::EqualName)
|
|
1868 && !f1->isFinalInCpp()
|
|
1869 && f2->isFinalInCpp()) {
|
|
1870 *f2 += AbstractMetaAttributes::FinalOverload;
|
|
1871 // qDebug() << f2 << f2->implementingClass()->name() << "::" << f2->name() << f2->arguments().size() << " vs " << f1 << f1->implementingClass()->name() << "::" << f1->name() << f1->arguments().size();
|
|
1872 // qDebug() << " " << f2;
|
|
1873 // AbstractMetaArgumentList f2Args = f2->arguments();
|
|
1874 // foreach (AbstractMetaArgument *a, f2Args)
|
|
1875 // qDebug() << " " << a->type()->name() << a->name();
|
|
1876 // qDebug() << " " << f1;
|
|
1877 // AbstractMetaArgumentList f1Args = f1->arguments();
|
|
1878 // foreach (AbstractMetaArgument *a, f1Args)
|
|
1879 // qDebug() << " " << a->type()->name() << a->name();
|
|
1880
|
|
1881 }
|
|
1882 }
|
|
1883 }
|
|
1884 }
|
|
1885
|
|
1886 setFunctions(funcs);
|
|
1887 }
|
|
1888
|
|
1889
|
|
1890 QString AbstractMetaType::minimalSignature() const
|
|
1891 {
|
|
1892 QString minimalSignature;
|
|
1893 if (isConstant())
|
|
1894 minimalSignature += "const ";
|
|
1895 minimalSignature += typeEntry()->qualifiedCppName();
|
|
1896 if (hasInstantiations()) {
|
|
1897 QList<AbstractMetaType *> instantiations = this->instantiations();
|
|
1898 minimalSignature += "<";
|
|
1899 for (int i=0;i<instantiations.size();++i) {
|
|
1900 if (i > 0)
|
|
1901 minimalSignature += ",";
|
|
1902 minimalSignature += instantiations.at(i)->minimalSignature();
|
|
1903 }
|
|
1904 minimalSignature += ">";
|
|
1905 }
|
|
1906
|
|
1907 if (isReference())
|
|
1908 minimalSignature += "&";
|
|
1909 for (int j=0; j<indirections(); ++j)
|
|
1910 minimalSignature += "*";
|
|
1911
|
|
1912 return minimalSignature;
|
|
1913 }
|
|
1914
|
|
1915 bool AbstractMetaType::hasNativeId() const
|
|
1916 {
|
|
1917 return (isQObject() || isValue() || isObject()) && typeEntry()->isNativeIdBased();
|
|
1918 }
|
|
1919
|
|
1920
|
|
1921 /*******************************************************************************
|
|
1922 * Other stuff...
|
|
1923 */
|
|
1924
|
|
1925
|
|
1926 AbstractMetaEnum *AbstractMetaClassList::findEnum(const EnumTypeEntry *entry) const
|
|
1927 {
|
|
1928 Q_ASSERT(entry->isEnum());
|
|
1929
|
|
1930 QString qualified_name = entry->qualifiedCppName();
|
|
1931 int pos = qualified_name.lastIndexOf("::");
|
|
1932
|
|
1933 QString enum_name;
|
|
1934 QString class_name;
|
|
1935
|
|
1936 if (pos > 0) {
|
|
1937 enum_name = qualified_name.mid(pos + 2);
|
|
1938 class_name = qualified_name.mid(0, pos);
|
|
1939 } else {
|
|
1940 enum_name = qualified_name;
|
|
1941 class_name = TypeDatabase::globalNamespaceClassName(entry);
|
|
1942 }
|
|
1943
|
|
1944 AbstractMetaClass *meta_class = findClass(class_name);
|
|
1945 if (!meta_class) {
|
|
1946 ReportHandler::warning(QString("AbstractMeta::findEnum(), unknown class '%1' in '%2'")
|
|
1947 .arg(class_name).arg(entry->qualifiedCppName()));
|
|
1948 return 0;
|
|
1949 }
|
|
1950
|
|
1951 return meta_class->findEnum(enum_name);
|
|
1952 }
|
|
1953
|
|
1954 AbstractMetaEnumValue *AbstractMetaEnumValueList::find(const QString &name) const
|
|
1955 {
|
|
1956 for (int i=0; i<size(); ++i) {
|
|
1957 if (name == at(i)->name())
|
|
1958 return at(i);
|
|
1959 }
|
|
1960 return 0;
|
|
1961 }
|
|
1962
|
|
1963 AbstractMetaEnumValue *AbstractMetaClassList::findEnumValue(const QString &name) const
|
|
1964 {
|
|
1965 QStringList lst = name.split(QLatin1String("::"));
|
|
1966
|
|
1967 Q_ASSERT_X(lst.size() == 2, "AbstractMetaClassList::findEnumValue()", "Expected qualified enum");
|
|
1968
|
|
1969
|
|
1970 QString prefixName = lst.at(0);
|
|
1971 QString enumName = lst.at(1);
|
|
1972
|
|
1973 AbstractMetaClass *cl = findClass(prefixName);
|
|
1974 if (cl)
|
|
1975 return cl->findEnumValue(enumName, 0);
|
|
1976
|
|
1977 ReportHandler::warning(QString("no matching enum '%1'").arg(name));
|
|
1978 return 0;
|
|
1979 }
|
|
1980
|
|
1981 /*!
|
|
1982 * Searches the list after a class that mathces \a name; either as
|
|
1983 * C++, Java base name or complete Java package.class name.
|
|
1984 */
|
|
1985
|
|
1986 AbstractMetaClass *AbstractMetaClassList::findClass(const QString &name) const
|
|
1987 {
|
|
1988 if (name.isEmpty())
|
|
1989 return 0;
|
|
1990
|
|
1991 foreach (AbstractMetaClass *c, *this) {
|
|
1992 if (c->qualifiedCppName() == name)
|
|
1993 return c;
|
|
1994 }
|
|
1995
|
|
1996 foreach (AbstractMetaClass *c, *this) {
|
|
1997 if (c->fullName() == name)
|
|
1998 return c;
|
|
1999 }
|
|
2000
|
|
2001 foreach (AbstractMetaClass *c, *this) {
|
|
2002 if (c->name() == name)
|
|
2003 return c;
|
|
2004 }
|
|
2005
|
|
2006 return 0;
|
|
2007 }
|
|
2008
|
|
2009 ArgumentReplace *ArgumentReplace::m_instance = 0;
|
|
2010
|
|
2011 ArgumentReplace::ArgumentReplace()
|
|
2012 {
|
|
2013 }
|
|
2014
|
|
2015 void ArgumentReplace::init()
|
|
2016 {
|
|
2017 if (m_instance)
|
|
2018 return;
|
|
2019
|
|
2020 m_instance = new ArgumentReplace();
|
|
2021 m_instance->data["version"] = "_version";
|
|
2022 m_instance->data["parent"] = "_parent";
|
|
2023 m_instance->data["delegate"] = "_delegate";
|
|
2024 m_instance->data["align"] = "_align";
|
|
2025 m_instance->data["in"] = "_in";
|
|
2026 m_instance->data["out"] = "_out";
|
|
2027 m_instance->data["scope"] = "_scope";
|
|
2028 m_instance->data["default"] = "_default";
|
39
|
2029 m_instance->data["body"] = "_body";
|
1
|
2030 }
|
|
2031
|
|
2032 QString ArgumentReplace::translate(QString arg)
|
|
2033 {
|
|
2034 if (m_instance->data.contains(arg))
|
|
2035 return m_instance->data[arg];
|
|
2036 else
|
|
2037 return arg;
|
|
2038 }
|